bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 Delphi MDI From使用PackageLoad建立Child Form
查看: 4939|回復: 0
go

MDI From使用PackageLoad建立Child Form [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 2007-3-6 15:13 |只看該作者 |倒序瀏覽 |打印
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、 添加一個導出過程,用於創建子表單的實例:

  1. procedure TPackageMDIChildForm.FormClose (Sender: TObject; var Action: TCloseAction);
  2. begin
  3.   //since this is an MDI child, make sure
  4.   //it gets closed when the user
  5.   //clicks the x button.
  6.   Action := caFree;
  7. end;

  8. procedure ExecuteChild;
  9. begin
  10.   TPackageMDIChildForm.Create(Application);
  11. end;

  12. exports
  13.   //NOTE!! The export name
  14.   //is CASE SENSITIVE
  15.   ExecuteChild;
  16. end.
複製代碼


重新回到MDI主程序,以下是MDI主表單的所有代碼:

  1. type

  2. //signature of the "ExecuteChild"
  3. //procedure from the Package
  4. TExecuteChild = procedure;

  5. TMainForm = class(TForm)
  6. ...
  7. private
  8.   PackageModule : HModule;
  9.   ExecuteChild : TExecuteChild;
  10.   procedure PackageLoad;
  11. end;

  12. var
  13.   MainForm: TMainForm;

  14. implementation

  15. {$R *.dfm}

  16. procedure TMainForm.PackageLoad;
  17. begin
  18.   //try loading the package
  19.   //(let's presume it's in the same
  20.   //folder, where the main app. exe is)
  21.   PackageModule := LoadPackage('MDIPackage.bpl');


  22.   //if loaded, try locating
  23.   //the ExecuteChild procedure
  24.   if PackageModule <> 0 then
  25.     try
  26.       @ExecuteChild := GetProcAddress(PackageModule,'ExecuteChild');
  27.     except
  28.       //display an error message if we fail
  29.       ShowMessage ('Package not found');
  30.     end;
  31. end;

  32. //menu click
  33. procedure TMainForm.mnuCallFromDLLClick(Sender: TObject);
  34. begin
  35.   //lazzy load package
  36.   if PackageModule = 0 then PackageLoad;
  37.   
  38.   //if the ExecuteChild procedure
  39.   //was found in the package, call it
  40.   if Assigned(ExecuteChild) then ExecuteChild;
  41. end;

  42. procedure TMainForm.FormDestroy(Sender: TObject);
  43. begin
  44.   //if the package was loaded,
  45.   //make sure to free the resources
  46.   if PackageModule <> 0 then
  47.     UnloadPackage(PackageModule);
  48. end;
複製代碼
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2025-5-2 17:37 , Processed in 0.017249 second(s), 10 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.