📄 ucatexpert.pas
字号:
TComboBox, TSetButton);
var Option :Cardinal; //index of the option to edit
Descr :TOptionDescription; //description of the option
AttrText :String; //attributes of the options
Attribute :TOptionOption; //counter through attributes
Value :TOptionValue; //value of the option
begin
if Assigned(Node) and (Node.ImageIndex = Ord(iiOption)) and
(Node <> FLastNode) then //new node of an option selected?
begin
SaveOption(True); //save currently edited option
Option := Cardinal(Node.Data); //get index of the option
FOptions.Description(Option, Descr); //get its description
EditName.Text := Descr.Name; //show general values
EditCategory.Text := Descr.Category;
//show value of the
EditDefaultValue.Text := ValueToString(Descr.DefaultValue, Descr);
StatusBar.Panels[0].Text := Descr.Description;
AttrText := ''; //no attributes so far
for Attribute := Low(Attribute) to High(Attribute) do
if Attribute in Descr.Options then //for each attribute
begin
if AttrText <> '' then //not the first one?
AttrText := AttrText + ', '; //add a separator
AttrText := AttrText + OptionOptionTexts[Attribute]; //show attribute
end;
EditAttributes.Text := AttrText;
//get the class in which the option is defined
EditClass.Text := FOptions.Topic(Option);
try
FEditControl.Free; //free the component
finally
FEditControl := nil;
end;
//create new component
FEditControl := EditType[Descr.DataType].Create(Self);
FEditControl.Parent := GroupBoxValue; //show on this form
FEditControl.HelpContext := GroupBoxValue.HelpContext;
FEditControl.Hint := 'The current value of the selected option. Pressing F3 will focus the control.';
Value := FOptions.Option[Option]; //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(FEditControl).MaxLength := Descr.StrMaxLen;
TEdit(FEditControl).Text := Value.StrData;
end;
otBoolean: begin
TCheckBox(FEditControl).Caption := Descr.Name;
TCheckBox(FEditControl).Checked := Value.BoolData;
end;
otInteger: begin
{$IFNDEF USENORMALSPINEDIT}
TGVSpinEdit(FEditControl).MaxValue := Descr.MaxInt;
TGVSpinEdit(FEditControl).MinValue := Descr.MinInt;
TGVSpinEdit(FEditControl).Value := Value.IntData;
{$ELSE}
// TSpinEdit(FEditControl).Max := Descr.MaxInt;
// TSpinEdit(FEditControl).Min := Descr.MinInt;
TSpinEdit(FEditControl).Value := Value.IntData;
{$ENDIF}
end;
otReal: begin
{$IFNDEF USENORMALSPINEDIT}
TExtSpinEdit(FEditControl).MaxValue := Descr.MaxReal;
TExtSpinEdit(FEditControl).MinValue := Descr.MinReal;
TExtSpinEdit(FEditControl).Value := Value.RealData;
{$ELSE}
// TSpinEdit(FEditControl).Max := Round(Descr.MaxReal * 1000);
// TSpinEdit(FEditControl).Min := Round(Descr.MinReal * 1000);
TSpinEdit(FEditControl).Value := Round(Value.RealData *
1000);
{$ENDIF}
end;
otEnumeration: begin
TComboBox(FEditControl).Style := csDropDownList;
TComboBox(FEditControl).Items := Descr.EnumNames;
TComboBox(FEditControl).ItemIndex := Value.EnumData;
TComboBox(FEditControl).DropDownCount := 16;
end;
otSet: TSetButton(FEditControl).Init(Descr.SetNames,
Value.SetData);
end;
//set the position of the component
FEditControl.SetBounds(EditDefaultValue.Left,
LabelValue.Top + (LabelValue.Height -
FEditControl.Height) div 2,
EditDefaultValue.Width, FEditControl.Height);
if Descr.DataType <> otEnumeration then
TEdit(FEditControl).OnKeyDown := EditValueKeyDown;
//focus the new component
// if FEditControl.Showing then
// FEditControl.SetFocus;
LabelValue.FocusControl := FEditControl;
FLastNode := Node; //save current node
{$IFNDEF LINUX}
//show the help text of the option
ShowHelpText(Option, Descr.HelpOptionIndex, Descr.Name);
{$ENDIF}
end; //if new node
end;
{Called when a node is collapsed.
~param Sender the sender of the event, ~[link TreeView]
~param Node the collapsed Node }
procedure TFormCatExpert.TreeViewCollapsed(Sender: TObject; Node: TTreeNode);
begin
Node.ImageIndex := Ord(iiClosed); //set closed image
Node.SelectedIndex := Ord(iiClosed);
end;
{Called when a node is expanded.
~param Sender the sender of the event, ~[link TreeView]
~param Node the expanded Node }
procedure TFormCatExpert.TreeViewExpanded(Sender: TObject; Node: TTreeNode);
begin
Node.ImageIndex := Ord(iiOpen); //set opened image
Node.SelectedIndex := Ord(iiOpen);
end;
{Called when the tree view is double clicked, toogles boolean values.
~param Sender the sender of the event, ~[link TreeView] }
procedure TFormCatExpert.TreeViewDblClick(Sender: TObject);
begin
//the current node double clicked?
if (FLastNode = TreeView.Selected) and assigned(FLastNode) then
if FEditControl is TCheckBox then //is a boolean value?
begin
//toggle the value
TCheckBox(FEditControl).Checked := not TCheckBox(FEditControl).Checked;
SaveOption(True);
end
else
if FEditControl is TComboBox then //is an item of an enumeration?
begin
if TComboBox(FEditControl).ItemIndex =
TComboBox(FEditControl).Items.Count - 1 then //select next item
TComboBox(FEditControl).ItemIndex := 0
else
TComboBox(FEditControl).ItemIndex := TComboBox(FEditControl).ItemIndex +
1;
SaveOption(True);
end;
end;
{Called when the user wants to edit the text (value) of a node in the tree
view.
~param Sender the sender of the event, ~[link TreeView]
~param Node the currently selected node to be edited
~param AllowEdit if the node can be edited }
procedure TFormCatExpert.TreeViewEditing(Sender: TObject; Node: TTreeNode; var AllowEdit: Boolean);
{$IFNDEF LINUX}
var Descr :TOptionDescription; //description of the option
S :String; //the value to edit
MaxLength :Integer; //maximum length of text
{$ENDIF}
begin
AllowEdit := Node.ImageIndex = Ord(iiOption); //node is an option?
{$IFNDEF LINUX}
if AllowEdit then //only then edit it
begin
//set the value of the option as the text to be edited
FOptions.Description(Cardinal(Node.Data), Descr);
S := ValueToString(FOptions.Option[Cardinal(Node.Data)], Descr);
MaxLength := SendMessage(TreeView_GetEditControl(TreeView.Handle),
EM_GETLIMITTEXT, 0, 0);
AllowEdit := (MaxLength = 0) or (MaxLength >= Length(S));
if AllowEdit then
SetWindowText(TreeView_GetEditControl(TreeView.Handle), PChar(S))
else
FEditControl.SetFocus; //use normal component instead
{ //this is also possible:
SendMessage(TreeView_GetEditControl(TreeView.Handle), WM_SETTEXT, 0,
LPARAM(PChar(S)));
}
end;
{$ENDIF}
end;
{Called when the button to pen a search dialog for options is clicked.
~param Sender the sender of the event, the button ~[link ButtonSearchDlg] }
procedure TFormCatExpert.ButtonSearchDlgClick(Sender: TObject);
begin
DoSearch(False); //just show the dialog
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 TFormCatExpert.EditValueKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Shift = []) and //is simply Up or Down?
{$IFNDEF LINUX}
((Key = VK_UP) or (Key = VK_DOWN))
{$ELSE}
((Key = Key_Up) or (Key = Key_Down))
{$ENDIF}
{$IFDEF USENORMALSPINEDIT}
and not (Sender is TSpinEdit)
{$ENDIF}
then
TreeView.SetFocus; //move to tree view, to change the option
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 TFormCatExpert.StatusBarDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
begin //just draw the text
StatusBar.Canvas.TextRect(Rect, Rect.Left, Rect.Top, Panel.Text);
end;
{Called when one of the components to select the options to show is changed.
~param Sender the sender of the event, ~[link RadioGroupShowOptions] or
~[link ComboBoxTopics] }
procedure TFormCatExpert.OptionTopicChanged(Sender: TObject);
var First :Integer; //index of first option to show
Last :Integer; //index after last option to show
begin
SaveOption(False); //save currently edited option
if (RadioGroupShowOptions.ItemIndex = 0) or //"up to" the topic or
(ComboBoxTopics.ItemIndex = 0) then //has no preceding topics?
First := 0 //start at first option
else //start at current topic's first option
First := Integer(ComboBoxTopics.Items.Objects[ComboBoxTopics.ItemIndex - 1]);
if RadioGroupShowOptions.ItemIndex = 2 then //"starting with" selected topic?
Last := FOptions.Count //up to the last option
else
//get number of options up to this class
Last := Integer(ComboBoxTopics.Items.Objects[ComboBoxTopics.ItemIndex]);
FillTreeView(First, Last); //show selected options
end;
{Called when the button to load the options from the default ini file of the
program is clicked.
~param Sender the sender of the event, ~[link ButtonLoadOptionsDefault] }
procedure TFormCatExpert.ButtonLoadOptionsDefaultClick(Sender: TObject);
begin
//load the options from the default ini file of the program
LoadOptions(ExtractFilePath(ParamStr(0)) + DefaultINIFile);
end;
{Called when the button to load the options from an ini file is clicked.
~param Sender the sender of the event, ~[link ButtonLoadOptionsFile] }
procedure TFormCatExpert.ButtonLoadOptionsFileClick(Sender: TObject);
begin
with TOpenDialog.Create(nil) do //create the file open - dialog
try
DefaultExt := 'ini';
Filter := 'Ini files and DelphiDoc-Projects (*.ini;*.' +
DDPDefaultExtension + ';*.' + DDGHDefaultExtension +
')|*.ini;*.' + DDPDefaultExtension + ';*.' +
DDGHDefaultExtension +
'|ini files (*.ini)|*.ini|DelphiDoc-Project (*.' +
DDPDefaultExtension + ')|*.' + DDPDefaultExtension +
'|DelphiDoc GUI Help project (*.' + DDGHDefaultExtension +
')|*.' + DDGHDefaultExtension + '|all files (*)|*';
InitialDir := GetCurrentDir;
Options := [ofHideReadOnly, ofFileMustExist, ofPathMustExist,
ofEnableSizing, ofShowHelp];
HelpContext := ButtonLoadOptionsFile.HelpContext;
Title := 'Load Options';
if Execute then //show the dialog; file selected?
LoadOptions(FileName); //load the options from the ini file
finally
Free; //free the dialog
end;
end;
{Called when the button to save the options into the default ini file of the
program is clicked.
~param Sender the sender of the event, ~[link ButtonSaveOptionsDefault] }
procedure TFormCatExpert.ButtonSaveOptionsDefaultClick(Sender: TObject);
begin
//save the options to the default ini file of the program
SaveOptions(ExtractFilePath(ParamStr(0)) + DefaultINIFile,
CheckBoxByHierarchy.Checked);
end;
{Called when the button to save the options into an ini file is clicked.
~param Sender the sender of the event, ~[link ButtonSaveOptionsFile] }
procedure TFormCatExpert.ButtonSaveOptionsFileClick(Sender: TObject);
begin
with TSaveDialog.Create(nil) do //create the file save - dialog
try
DefaultExt := 'ini';
Filter := 'Ini files and DelphiDoc-Projects (*.ini;*.' +
DDPDefaultExtension + ';*.' + DDGHDefaultExtension +
')|*.ini;*.' + DDPDefaultExtension + ';*.' +
DDGHDefaultExtension +
'|ini files (*.ini)|*.ini|DelphiDoc-Project (*.' +
DDPDefaultExtension + ')|*.' + DDPDefaultExtension +
'|DelphiDoc GUI Help project (*.' + DDGHDefaultExtension +
')|*.' + DDGHDefaultExtension + '|all files (*)|*';
InitialDir := GetCurrentDir;
Options := [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist,
ofEnableSizing, ofShowHelp];
HelpContext := ButtonSaveOptionsFile.HelpContext;
Title := 'Save Options';
if Execute then //show the dialog; file selected?
//save the options to the ini file
SaveOptions(FileName, CheckBoxByHierarchy.Checked);
finally
Free; //free the dialog
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -