📄 uexpert.pas
字号:
otReal: Value.RealData := TSpinEdit(Control).Value / 1000;
{$ENDIF}
otEnumeration: Value.EnumData := TComboBox(Control).ItemIndex;
otSet: Value.SetData := TSetButton(Control).Value;
end;
FOptions.Option[Index] := Value; //set the new value
Value := FOptions.Option[Index]; //show the new value
if ooChangesOtherOptions in Descr.Options then //other options changed, too?
for i := 0 to StringGridOptions.RowCount - 2 do //for each option
begin
FOptions.Description(i, Descr); //get its description
StringGridOptions.Cells[3, i + 1] := ValueToString(FOptions.Option[i],
Descr); //refresh value
end
else
//show value of this option
StringGridOptions.Cells[3, Index + 1] := ValueToString(Value, Descr);
end;
{Gets a new component to edit the current option and initializes it.
~param Index the index of the option to edit
~result the control to edit the option }
function TFormExpert.GetEditControlAndData(Index: Cardinal): TEditComponent;
//control classes for each type of the options
const EditType: array[TOptionType] of TEditComponentClass =
(TEdit, TCheckBox,
{$IFNDEF USENORMALSPINEDIT}
TGVSpinEdit, TExtSpinEdit,
{$ELSE}
TSpinEdit, TSpinEdit,
{$ENDIF}
TComboBox, TSetButton);
var Descr :TOptionDescription; //description of the option
Value :TOptionValue; //value of the option
begin
FOptions.Description(Index, Descr); //get type of the option
//create control to edit this type of options
Result := EditType[Descr.DataType].Create(Self);
Result.Parent := Self; //show on this form
Result.HelpContext := StringGridOptions.HelpContext;
Value := FOptions.Option[Index]; //get value of the option
case Descr.DataType of //set value and extended data of
otString: begin //the option depending on its type
if Descr.StrMaxLen <> 0 then
TEdit(Result).MaxLength := Descr.StrMaxLen;
TEdit(Result).Text := Value.StrData;
end;
otBoolean: begin
TCheckBox(Result).Caption := Descr.Name;
TCheckBox(Result).Checked := Value.BoolData;
end;
otInteger: begin
{$IFNDEF USENORMALSPINEDIT}
TGVSpinEdit(Result).MaxValue := Descr.MaxInt;
TGVSpinEdit(Result).MinValue := Descr.MinInt;
TGVSpinEdit(Result).Value := Value.IntData;
{$ELSE}
// TSpinEdit(Result).Max := Descr.MaxInt;
// TSpinEdit(Result).Min := Descr.MinInt;
TSpinEdit(Result).Value := Value.IntData;
{$ENDIF}
end;
otReal: begin
{$IFNDEF USENORMALSPINEDIT}
TExtSpinEdit(Result).MaxValue := Descr.MaxReal;
TExtSpinEdit(Result).MinValue := Descr.MinReal;
TExtSpinEdit(Result).Value := Value.RealData;
{$ELSE}
// TSpinEdit(Result).Max := Round(Descr.MaxReal * 1000);
// TSpinEdit(Result).Min := Round(Descr.MinReal * 1000);
TSpinEdit(Result).Value := Round(Value.RealData * 1000);
{$ENDIF}
end;
otEnumeration: begin
TComboBox(Result).Style := csDropDownList;
TComboBox(Result).Items := Descr.EnumNames;
TComboBox(Result).ItemIndex := Value.EnumData;
TComboBox(Result).DropDownCount := 16;
end;
otSet: TSetButton(Result).Init(Descr.SetNames, Value.SetData);
end;
end;
{Called when a key is pressed in ~[link FEditControl]. Up and Down will change
the currently edited option.
~param Sender the sender of the event, ~[link FEditControl]
~param Key code of the pressed key (only Up and Down are handled)
~param Shift state of special modifying keys }
procedure TFormExpert.EditControlKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
{$IFNDEF LINUX}
const Up = VK_UP;
Down = VK_DOWN;
{$ELSE}
const Up = Key_Up;
Down = Key_Down;
{$ENDIF}
begin
if (Shift = []) and //is Up or Down and matching option available?
(((Key = Up) and (StringGridOptions.Row > 1)) or
((Key = Down) and
(StringGridOptions.Row < StringGridOptions.RowCount - 1)))
{$IFDEF USENORMALSPINEDIT}
and not (Sender is TSpinEdit)
{$ENDIF}
then
StringGridOptions.SetFocus; //move to list, to change the option
end;
{Will be called, when the form is showed.
~param Sender the sender of the event, the form }
procedure TFormExpert.FormShow(Sender: TObject);
begin
if assigned(FEditControl) then //activate the control to edit the option
FEditControl.SetFocus;
end;
{Called when the form is resized. Adjusts the width of the last column.
~param Sender the sender of the event, the form }
procedure TFormExpert.FormResize(Sender: TObject);
var Count :Integer; //number of columns in the list
Width :Integer; //width of all columns
i :Integer; //counter through all columns
begin
Count := StringGridOptions.ColCount - 1; //get number of columns
Width := Count; //initialize with width of lines
for i := 0 to Count do //get width of all columns but last
inc(Width, StringGridOptions.ColWidths[i]);
//calculate width of the last column
i := (StringGridOptions.Width - Width) + StringGridOptions.ColWidths[Count];
if (Width < StringGridOptions.Width) or (i > 50) then
StringGridOptions.ColWidths[Count] := i; //set width of the last column
end;
{Called when another row in the in the list is selected.
~param Sender the sender of the event, ~[link StringGridOptions]
~param ACol, ARow the selected cell in the list
~param CanSelect if the cell can be selected }
procedure TFormExpert.StringGridOptionsSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
var Position :TRect; //position of the selected cell
begin
CanSelect := ACol = 3; //cell of the value of an option?
if CanSelect then //only if it is a value
begin
if assigned(FEditControl) then //option currently edited?
SaveData(StringGridOptions.Row - 1, FEditControl); //save the value
try
FEditControl.Free; //save the old component
finally
FEditControl := nil;
end;
//get component to edit this option
FEditControl := GetEditControlAndData(ARow - 1);
if StringGridOptions.ColWidths[3] < 80 then //set width of the component
FEditControl.Width := 80
else
FEditControl.Width := StringGridOptions.ColWidths[3] + 1;
//get position of the cell and set the position of the component
Position := StringGridOptions.CellRect(3, ARow);
TEdit(FEditControl).OnKeyDown := EditControlKeyDown;
if StringGridOptions.RowHeights[ARow] > FEditControl.Height then
inc(Position.Top, StringGridOptions.RowHeights[ARow] - FEditControl.Height);
FEditControl.Left := Position.Left - 1;
FEditControl.Top := Position.Top - 1;
//show description of the option
StatusBar.Panels[0].Text := StringGridOptions.Cells[5, ARow];
if FEditControl.Showing then
FEditControl.SetFocus; //focus the new component
end; //if CanSelect
end;
{Called when a key is released on the list (or after it has been pressed in the
component to edit the option).
~param Sender the sender of the event, ~[link StringGridOptions]
~param Key code of the pressed key (only Up and Down are handled)
~param Shift state of special modifying keys }
procedure TFormExpert.StringGridOptionsKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
{$IFNDEF LINUX}
const Up = VK_UP;
Down = VK_DOWN;
{$ELSE}
const Up = Key_Up;
Down = Key_Down;
{$ENDIF}
begin
if (Shift = []) and //is Up or Down and option available?
(((Key = Up) and (StringGridOptions.Row > 1)) or
((Key = Down) and
(StringGridOptions.Row < StringGridOptions.RowCount - 1))) then
if Key = Up then //got to the new option
StringGridOptions.Row := StringGridOptions.Row - 1
else
StringGridOptions.Row := StringGridOptions.Row + 1
else
if assigned(FEditControl) then //focus the old component to edit the option
FEditControl.SetFocus;
end;
{Called when the list is scrolled. Scrolls also the component to edit the
option.
~param Sender the sender of the event, ~[link StringGridOptions] }
procedure TFormExpert.StringGridOptionsTopLeftChanged(Sender: TObject);
var Position :TRect; //position fo the cell
begin
//get position of the current cell
Position := StringGridOptions.CellRect(3, StringGridOptions.Row);
if StringGridOptions.RowHeights[StringGridOptions.Row] >
FEditControl.Height then //adjust position by height of the component
inc(Position.Top, StringGridOptions.RowHeights[StringGridOptions.Row] -
FEditControl.Height);
FEditControl.Left := Position.Left - 1; //set new position
FEditControl.Top := Position.Top - 1;
end;
{Called when the text of the status bas has to be drawn (or it will truncate it
after 255 characters).
~param StatusBar the sender of the event, ~[link .StatusBar]
~param Panel the panel whose text should be drawn, StatusBar.Panel[0]
~param Rect the rect where to draw the text }
procedure TFormExpert.StatusBarDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
begin //just draw the text
StatusBar.Canvas.TextRect(Rect, Rect.Left, Rect.Top, Panel.Text);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -