代碼示例:你是真的對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 是一個Class of Class, 也就是類的類
比如
TFormClass = Class of TForm;
但是不同于:TFormClass = Class( TForm ); 這是兩個概念!
而 EditorClassList 里面存放的就是 類的類的列表;
Editor := EditorClass.Create;
Create是類方法,而不是對象方法,所以可以由 EditorClass來創建EditorClass的一個實例
補充:
TStepEditor = Class( TObject )
...
End;
TStepEditorClass = Class of TStepEditor;
Object Inspector 為什么能夠提供一個方便的編輯環境?
為什么不同的字段,供選擇的值不一樣,校驗的方式不一樣,彈出的編輯框
不一樣?因為根據不同的字段類型,注冊了不同的屬性編輯器 Propety Editor;
簡化Delphi提供的注冊屬性編輯器的函數,可以描述為以下:
RegisteryPropertyEditor( PropertyFieldType, EditorClass );
^此處為類型名,如 Bool , Integer, ...等等
^此處為對應的編輯器的類名,注意,不是類名的字符描述
實際運行的時候,用戶點擊Object Inspector 的一個字段的時候,
Delphi內部就搜索該字段類型對應的編輯器類;然后由找到的類的類,創建該類的一個實例;
進行相關的操作(決定是否有下拉框,是否有一個按鈕等等)
新聞熱點
疑難解答
圖片精選