Code example: Do you really understand Delphi?

zhaozj2021-02-11  226

Code example: Do you really understand Delphi?

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, which is class, such as TFormClass = Class of TForm; but is different from: tformclass = class (tform); this is two concepts! The editorclasslist stores is a list of class classes; editor: = editorclass.create; create is a class method, not an object method, so an instance of editorclass can be created by editorclass

Supplement: tstepeditor = class (TOBJECT) ... END; TSTEPEDITORCLASS = Class of Tstepeditor

Why can Object INSPECTOR provide a convenient editing environment? Why is different fields, the selected value is different, the verification method is different, the pop-up edit box is different? Because of the different field types, different attribute editor ProPivity Editor; Simplify the function of the registration attribute editor provided by Delphi, it can be described as following: registerpropertyEditor (PropertyFieldType, EditorClass); ^ This is the type name, such as Bool, Integer, ..., etc. ^ here, the class name of the corresponding editor, note that when the character describes the actual operation, the user can click on the Object Inspector to search the field type corresponding to the field type Editor class; then create an instance of such a class by the class found; perform related operations (decide if there is a drop box, have a button, etc.)

More articles

转载请注明原文地址:https://www.9cbs.com/read-5335.html

New Post(0)