Code example: Do you really know Delphi well?
PRocedure StepEditor( strgrid: TStringGrid; Step: TStep );
var
sValue, sField: string;
EditorClass: TStepEditorClass;
Editor: TStepEditor;
begin
sField := strgrid.Cells[0, strgrid.Selection.Top];
sValue := strgrid.Cells[1, strgrid.Selection.Top];
EditorClass := EditorClassList.Editors[ sField ];
Editor := EditorClass.Create;
Editor.Field := sField;
Editor.Step := Step;
Editor.Edit(sValue);
Editor.Free;
strgrid.Cells[ 1, strgrid.Selection.Top ] := sValue;
end;
EditorClass is a Class of Class, that is, a class of classes
for example
TFormClass = Class of TForm;
But it is different from: TFormClass = Class(TForm); These are two concepts!
The EditorClassList stores a list of classes;
Editor := EditorClass.Create;
Create is a class method, not an object method, so an instance of EditorClass can be created from EditorClass
Replenish:
TStepEditor = Class( TObject )
...
End;
TStepEditorClass = Class of TStepEditor;
Why can Object Inspector provide a convenient editing environment?
Why do different fields have different values for selection, different verification methods, and pop-up edit boxes?
no the same? Because different property editors are registered according to different field types;
Simplifying the function of registering the property editor provided by Delphi can be described as follows:
RegisteryPropertyEditor( PropertyFieldType, EditorClass );
^Here is the type name, such as Bool, Integer, ...etc.
^Here is the class name of the corresponding editor. Note that it is not the character description of the class name.
When actually running, when the user clicks a field in the Object Inspector,
Delphi internally searches for the editor class corresponding to the field type; then creates an instance of the class from the found class;
Perform related operations (deciding whether there is a drop-down box, whether there is a button, etc.)
More articles