嵌套的FORMtype TbsTest1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end;function ShowMDIForm(App: TApplication;AParentWindows:THandle): THandle; stdcall; exports ShowMDIForm;var bsTest1: TbsTest1;implementation{$R *.dfm}function ShowMDIForm(App: TApplication;AParentWindows:THandle): THandle; begin Application := App; with TbsTest1.Create(App) do try FormStyle:=fsNormal; ParentWindow:=AParentWindows; Align := alClient; BorderStyle := bsNone; BorderIcons := []; Show; result := Handle; except Result := 0; end; end;procedure TbsTest1.Button1Click(Sender: TObject); begin ShowMessage('111212'); end;procedure TbsTest1.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end; 主界面 TShowMDIForm = function(App : TApplication;AParentWindows:THandle):THandle; stdcall;function TbsMainForm.LoadPackageB(tempBpl: string): Boolean; var pProc : TShowMDIForm; tempSheet:TcxTabSheet; begin Result:=True; bplH := LoadPackage(tempBpl); if IsWindow(bplFormH) then try ShowWindow(bplFormH, SW_SHOW); exit; except on E: Exception do raise Exception.Create(e.Message); end; if bplH = 0 then raise Exception.Create('无法获取待使用的包文件句柄!'); pProc := getprocaddress(bplH, 'ShowMDIForm'); ShowMessage('start'); tempSheet:=GetTabSheet(tempBpl); if Assigned(pProc) then bplFormH := pProc(Application,tempSheet.Handle); ShowMessage('end'); end;function TbsMainForm.GetTabSheet(tabName: string): TcxTabSheet; var tempSheet:TcxTabSheet; tempName:string; tempDirName:string; i:Integer; begin Result:=nil; if tabName='' then begin Exit; end; tempDirName:=ExtractFileDir(ParamStr(0)); tempName:=StringReplace(tabName,tempDirName+'\','',[rfReplaceAll]); tempName:=Copy(tempName,1,pos('.',tempName)-1); if tabSheetList.IndexOf('cx'+tempName)<>-1 then begin //存在 则SHOW for i := 0 to MainPG.PageCount-1 do begin if MainPG.Pages[i].Name=('cx'+tempName) then begin MainPG.ActivePage:=MainPG.Pages[i]; Result:=MainPG.Pages[i]; end; end; end else begin //不存在 try tempSheet:=TcxTabSheet.Create(MainPG); with tempSheet do begin AllowCloseButton:=True; Caption:=tempName; Enabled:=True; Name:='cx'+tempName; Visible:=True; Parent:=MainPG; PageControl:=MainPG; ParentWindow:=MainPG.Handle; TabVisible:=True; end; tabSheetList.Add(tempSheet.Name); Result:=tempSheet; MainPG.ActivePage:=tempSheet; except end; end; end;
FORM的父窗体SHEET关闭了,FORM还需要写关闭事件么?
TbsTest1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;function ShowMDIForm(App: TApplication;AParentWindows:THandle): THandle; stdcall;
exports
ShowMDIForm;var
bsTest1: TbsTest1;implementation{$R *.dfm}function ShowMDIForm(App: TApplication;AParentWindows:THandle): THandle;
begin
Application := App;
with TbsTest1.Create(App) do
try
FormStyle:=fsNormal;
ParentWindow:=AParentWindows;
Align := alClient;
BorderStyle := bsNone;
BorderIcons := [];
Show;
result := Handle;
except
Result := 0;
end;
end;procedure TbsTest1.Button1Click(Sender: TObject);
begin
ShowMessage('111212');
end;procedure TbsTest1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
主界面 TShowMDIForm = function(App : TApplication;AParentWindows:THandle):THandle; stdcall;function TbsMainForm.LoadPackageB(tempBpl: string): Boolean;
var
pProc : TShowMDIForm;
tempSheet:TcxTabSheet;
begin
Result:=True;
bplH := LoadPackage(tempBpl);
if IsWindow(bplFormH) then
try
ShowWindow(bplFormH, SW_SHOW);
exit;
except on E: Exception do
raise Exception.Create(e.Message);
end;
if bplH = 0 then
raise Exception.Create('无法获取待使用的包文件句柄!');
pProc := getprocaddress(bplH, 'ShowMDIForm');
ShowMessage('start');
tempSheet:=GetTabSheet(tempBpl);
if Assigned(pProc) then
bplFormH := pProc(Application,tempSheet.Handle);
ShowMessage('end');
end;function TbsMainForm.GetTabSheet(tabName: string): TcxTabSheet;
var tempSheet:TcxTabSheet;
tempName:string;
tempDirName:string;
i:Integer;
begin
Result:=nil;
if tabName='' then
begin
Exit;
end;
tempDirName:=ExtractFileDir(ParamStr(0));
tempName:=StringReplace(tabName,tempDirName+'\','',[rfReplaceAll]);
tempName:=Copy(tempName,1,pos('.',tempName)-1);
if tabSheetList.IndexOf('cx'+tempName)<>-1 then
begin
//存在 则SHOW
for i := 0 to MainPG.PageCount-1 do
begin
if MainPG.Pages[i].Name=('cx'+tempName) then
begin
MainPG.ActivePage:=MainPG.Pages[i];
Result:=MainPG.Pages[i];
end;
end;
end
else
begin
//不存在
try
tempSheet:=TcxTabSheet.Create(MainPG);
with tempSheet do
begin
AllowCloseButton:=True;
Caption:=tempName;
Enabled:=True;
Name:='cx'+tempName;
Visible:=True;
Parent:=MainPG;
PageControl:=MainPG;
ParentWindow:=MainPG.Handle;
TabVisible:=True;
end;
tabSheetList.Add(tempSheet.Name);
Result:=tempSheet;
MainPG.ActivePage:=tempSheet;
except end;
end;
end;