bestlong 怕失憶論壇
標題:
MDI From使用PackageLoad建立Child Form
[打印本頁]
作者:
bestlong
時間:
2007-3-6 15:13
標題:
MDI From使用PackageLoad建立Child Form
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;
複製代碼
歡迎光臨 bestlong 怕失憶論壇 (http://www.bestlong.idv.tw/)
Powered by Discuz! X1.5