求一个 简单的DLL封装的 窗口 操作其它窗口的实例!试过很多方法,可以正确显示出DLL中封装的窗口,显示出的窗口也能够正确操作自身,但是一操作其它的窗口就会出错,
求一份可以正确操作其它窗口的DemoDLL代码如下:library mydll;uses
SysUtils,
Classes,
dunit in 'dunit.pas' {dForm};{$R *.res}
Procedure CallDll();stdcall;
begin
dForm := TdForm.Create(nil);
try
dForm.Show;
except
dForm.Free;
end;
end;
exports
CallDll;
begin
end.
dunit.pas代码如下 封装进DLL中的窗体unit dunit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MainForm1;type
TdForm = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
dForm: TdForm;implementation{$R *.dfm}procedure TdForm.Button2Click(Sender: TObject);
begin
close;
end;procedure TdForm.Button1Click(Sender: TObject);
begin
Form1.Button1.Caption := '标题已被DLL窗体改变'; //改变其它窗体上的按钮
end;procedure TdForm.Button3Click(Sender: TObject);
begin
self.Button1.Caption := '改变自身窗体按钮一';
end;end.
测试DLL窗体的程序,代码如下:unit MainForm1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
Procedure CallDll();stdcall;
external 'mydll.dll'; {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
CallDll();
end;end.
有实例的希望发一个给看一下,,,或者帮忙看一下我代码中是否有少写或写错的地方,以
致DLL窗口在操作其它窗口的时候了错
求一份可以正确操作其它窗口的DemoDLL代码如下:library mydll;uses
SysUtils,
Classes,
dunit in 'dunit.pas' {dForm};{$R *.res}
Procedure CallDll();stdcall;
begin
dForm := TdForm.Create(nil);
try
dForm.Show;
except
dForm.Free;
end;
end;
exports
CallDll;
begin
end.
dunit.pas代码如下 封装进DLL中的窗体unit dunit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MainForm1;type
TdForm = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
dForm: TdForm;implementation{$R *.dfm}procedure TdForm.Button2Click(Sender: TObject);
begin
close;
end;procedure TdForm.Button1Click(Sender: TObject);
begin
Form1.Button1.Caption := '标题已被DLL窗体改变'; //改变其它窗体上的按钮
end;procedure TdForm.Button3Click(Sender: TObject);
begin
self.Button1.Caption := '改变自身窗体按钮一';
end;end.
测试DLL窗体的程序,代码如下:unit MainForm1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
Procedure CallDll();stdcall;
external 'mydll.dll'; {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
CallDll();
end;end.
有实例的希望发一个给看一下,,,或者帮忙看一下我代码中是否有少写或写错的地方,以
致DLL窗口在操作其它窗口的时候了错
[email protected]
简单点给主窗体发消息吧,复杂点就用接口吧~
begin
Application.Handle:=App;
end;
dForm := TdForm.Create(nil);
改为dForm := TdForm.Create(Application);测试调用加上这句 procedure SynAPP(App:THandle);stdcall;external 'mydll.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
SynApp(Application.Handle);
CallDll();
end;
试一下吧,应该可以了
的函数、过程封装进DLL,这样在运行的时候此控件在内存中就只有一个实例。 例如我想封装ADODATASET ADOCONNECTION ADOQUERY 等,