我试了,不行呀! 总是说‘CANNOT CREATE FROM. NO MDI FORMS ARE CURRENTLY ACTIVE’ 怎么办呀 我在主窗体上这么写的 procedure TForm1.A1Click(Sender: TObject); begin showform1(application.Handle); end; 一运行就出现了上面那句话
给你一个单元,是可以调用form的 library jiemian;uses SysUtils, forms, Classes, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} function showform:integer;stdcall; var form:tform1; begin form:=tform1.Create(application); result:=form.ShowModal; form.Free; end; exports showform;begin end. form1的代码是: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Label1: TLabel; Button1: TButton; Label2: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); begin close; end;end. 编完就能运行
这个我知道,调用非子窗体,我会,能调用。可是dll文件里的窗体如果是子窗体,我还是用非子窗体的方式在主程序里调用,就是不行呀 一调用就出现‘CANNOT CREATE FROM. NO MDI FORMS ARE CURRENTLY ACTIVE’这句话,奇怪了,我的主程序里有父窗体和子窗体的,我想在主程序里的子窗体上调用dll里的窗体作为主程序里父窗体的子窗体,那么主程序和dll文件应该怎么写呢,困惑…… 谢谢大家帮忙了!!!
Library showForm1
use
sysutils,classes,
{$r *.res}
exports
showForm1;
begin
end.
procedure showForm1(Ahandle:Thandle);
var
From1:TForm1;
begin
Application.handle:=Ahandle;
Form1:=TForm1.create(Application);
Form1.show;
end;
是这个吧?
怎么办呀
我在主窗体上这么写的
procedure TForm1.A1Click(Sender: TObject);
begin
showform1(application.Handle);
end;
一运行就出现了上面那句话
library jiemian;uses
SysUtils,
forms,
Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
function showform:integer;stdcall;
var
form:tform1;
begin
form:=tform1.Create(application);
result:=form.ShowModal;
form.Free;
end;
exports
showform;begin
end.
form1的代码是:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;end.
编完就能运行
一调用就出现‘CANNOT CREATE FROM. NO MDI FORMS ARE CURRENTLY ACTIVE’这句话,奇怪了,我的主程序里有父窗体和子窗体的,我想在主程序里的子窗体上调用dll里的窗体作为主程序里父窗体的子窗体,那么主程序和dll文件应该怎么写呢,困惑…… 谢谢大家帮忙了!!!
变通一下,只要在主程序里有主窗体了,在DLL中用不着再母子窗体了,只用一个普通窗体就可以。
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ToolWin, ComCtrls, Menus, ImgList;type
TMainForm = class(TForm)
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ImageList1: TImageList;
procedure fgf1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations } public
{ Public declarations }
procedure DllCall(Sender: TObject);
end; T_ProvaChild = procedure (ParentApplication: TApplication; parentform: TForm); stdcall;var
MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.DllCall(Sender: TObject);
var
DllHandle: THandle;
ProcAddr: FarProc;
ProvaChild: T_ProvaChild;
str,str1,str2 : string;
begin
str := (Sender as TToolButton).Caption ;
str1 := copy(str,1,pos('@',str)-1); // str1:=ProjectDll // DLL文件名
str2 := copy(str,pos('@',str)+1,length(str)); //str2:=ProvaChild DllHandle := LoadLibrary(PChar(str1));
if DllHandle <> 0 then
begin
ProcAddr := GetProcAddress(DllHandle, PChar(str2));
if Assigned(ProvaChild) then
begin
ProvaChild := ProcAddr;
ProvaChild(Application,Self);
end;
//**** freelibrary(DllHandle);//注意!!!注!!!*************
end;end;procedure TMainForm.fgf1Click(Sender: TObject);
begin
//DllCall;
end;procedure TMainForm.FormCreate(Sender: TObject);
begin
toolbutton1.caption:= ProjectDll@ProvaChild;
toolbutton1.OnClick := DllCall;
end;end.//DLL文件/////////////////////////////////library ProjectDll;uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
ubasStatusaaRoom in 'ubasStatusaaRoom.pas' {FbasStatusaaRoom};procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH then Application:=DllApplication;
end;procedure ProvaChild(ParentApplication: TApplication; ParentForm: TForm); export; stdcall;
begin
if not Assigned(FbasStatusaaRoom) then
begin
Application := ParentApplication;
FbasStatusaaRoom := TFbasStatusaaRoom.Create(nil);
FbasStatusaaRoom.MyParentForm := ParentForm;
FbasStatusaaRoom.MyParentApplication := ParentApplication;
end;
FbasStatusaaRoom.Show;
end;exports
ProvaChild;
begin
DllApplication:=Application;
DLLProc := @DLLUnloadProc;
end.//其中的一个子窗体/////////////////////////unit ubasStatusaaRoom;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, ExtCtrls, DB, DBClient, ImgList, Grids,
DBGridEh,ActiveX;type
TFbasStatusaaRoom = class(TForm)
Panel1: TPanel;
StatusBar1: TStatusBar;
ToolBar1: TToolBar;
tbfirst: TToolButton;
tbprev: TToolButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
MyParentForm: TForm;
MyParentApplication: TApplication;
end;var
FbasStatusaaRoom: TFbasStatusaaRoom;
implementation{$R *.dfm} procedure TFbasStatusaaRoom.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action := caFree;
FbasStatusaaRoom := nil ;
end;
end.