- 註冊時間
- 2006-3-13
- 最後登錄
- 2025-1-10
- 在線時間
- 673 小時
- 閱讀權限
- 200
- 積分
- 417
- 帖子
- 1107
- 精華
- 0
- UID
- 2
  
|
MDI From使用PackageLoad建立Child Form
1、 建立一個新的MDI應用程式。你可以使用(File - New - Other - Projects - MDI Application)
2、 確保Main Form的FormStyle屬性已經設置為fsMDIForm
3、 增加一個MainMenu控制項
4、 確保在產生應用程式的時候,是和package一起產生的。在Project – Options功能表中,選擇Packages選項,然後選中“Build with run-time packages”選項。你至少要選中rtl package和vcl package
在真正編碼前,首先生成該package,並且向其增加一個MDI子表單
1、 創建一個新的運行時package
2、 package增加一個TForm物件,確保該物件的FormStyle屬性已經設置為fsMDIChild
3、 添加一個導出過程,用於創建子表單的實例:
- procedure TPackageMDIChildForm.FormClose (Sender: TObject; var Action: TCloseAction);
- begin
- //since this is an MDI child, make sure
- //it gets closed when the user
- //clicks the x button.
- Action := caFree;
- end;
- procedure ExecuteChild;
- begin
- TPackageMDIChildForm.Create(Application);
- end;
- exports
- //NOTE!! The export name
- //is CASE SENSITIVE
- ExecuteChild;
- end.
複製代碼
重新回到MDI主程序,以下是MDI主表單的所有代碼:
- type
- //signature of the "ExecuteChild"
- //procedure from the Package
- TExecuteChild = procedure;
- TMainForm = class(TForm)
- ...
- private
- PackageModule : HModule;
- ExecuteChild : TExecuteChild;
- procedure PackageLoad;
- end;
- var
- MainForm: TMainForm;
- implementation
- {$R *.dfm}
- procedure TMainForm.PackageLoad;
- begin
- //try loading the package
- //(let's presume it's in the same
- //folder, where the main app. exe is)
- PackageModule := LoadPackage('MDIPackage.bpl');
- //if loaded, try locating
- //the ExecuteChild procedure
- if PackageModule <> 0 then
- try
- @ExecuteChild := GetProcAddress(PackageModule,'ExecuteChild');
- except
- //display an error message if we fail
- ShowMessage ('Package not found');
- end;
- end;
- //menu click
- procedure TMainForm.mnuCallFromDLLClick(Sender: TObject);
- begin
- //lazzy load package
- if PackageModule = 0 then PackageLoad;
-
- //if the ExecuteChild procedure
- //was found in the package, call it
- if Assigned(ExecuteChild) then ExecuteChild;
- end;
- procedure TMainForm.FormDestroy(Sender: TObject);
- begin
- //if the package was loaded,
- //make sure to free the resources
- if PackageModule <> 0 then
- UnloadPackage(PackageModule);
- end;
複製代碼 |
|