DataModule Designer instance |
|
axsoft
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:681 回覆:1056 積分:969 註冊:2002-03-13 發送簡訊給我 |
DataModule Designer instance 資料來源: www.delphi3000.com Question:
I can retreive instance of Designer for forms as their property "Designer", but how to retreive it for DataModule like objects? Answer: For receiving instance of Designer for forms you should just get form's property "Designer".
But how to receive the Designer instance if you have only DataModule's instance? It is very simply: the DataModule is an usual VCL component and its owner is hidden form, so for retreiving Designer instance of DataModule just retreive "Designer" property of DataModule's owner.
The function below demonstrates retreiving Designer instance for any form in your project by its name. This function is useful when Designer instance is necessary for your experts. Add these definitions:
{$IFDEF VER120} TFormDesigner= IFormDesigner; {$ENDIF} {$IFDEF VER125} TFormDesigner= IFormDesigner; {$ENDIF} {$IFDEF VER130} TFormDesigner= IFormDesigner; {$ENDIF} function GetDesigner(FToolServices: TIToolServices; FormName: string): TFormDesigner; var tmpC: TComponent; begin Result := nil; with FToolServices.GetFormModuleInterface(FormName).GetFormInterface.GetFormComponent do begin tmpC := GetComponentHandle; if (tmpC is TCustomForm) then begin // We have the usual form Result := TFormDesigner(TCustomForm(tmpC).Designer); Exit; end else // We have the DataModule or WebModule or something else Result := TFormDesigner(TCustomForm(tmpc.Owner).Designer); end; end; For receiving Designer without using ToolServices you can use following function: finction GetDesigner(AComp: TComponent): TFormDesigner; var tmpC: TComponent; begin Result = nil; if not Assigned(AComp) then Exit; if AComp is TCustomForm then Result := TFormDesigner(TCustomForm(AComp).Designer) else begin tmpC := AComp; while true do begin if Assigned(tmpC.Owner) then tmpC := tmpC.Owner else break; if tmpC is TCustomForm then begin Result := TFormDesigner(TCustomForm(AComp).Designer); break; end; end; end; end;網路志工聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]--- |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |