dll窗体设成主程序的子窗体

qq7118622 2009-10-30 10:34:27
主程序form1设为fsMDIForm,然后调用dll中的窗体(fsMDIChild),并设成主程序的子窗体,不成功,请教各位高手了...谢谢.
主程序:
private
dl_xm,dl_qx,joinstr:string;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
kc_handle:THandle;

implementation

{$R *.dfm}

procedure TForm1.FormResize(Sender: TObject);
begin

Image1.Left:=(form1.Panel1.Width-form1.Image1.Width) div 2;
Image1.Top:=(form1.Panel1.Height-image1.Height) div 2;
end;

procedure TForm1.N5Click(Sender: TObject);
var
kc:procedure(dl_xm,joinstr,dl_qx:string);stdcall;
begin
kc_handle:=LoadLibrary(PChar('kcsh_dll.dll'));
if kc_handle<=0 then
begin
Application.MessageBox('动态库不存在!','提示',64);
exit;
end
else
begin
try
@kc:=GetProcAddress(kc_handle,'kc_tj');
kc(Form1.dl_xm,Form1.joinstr,form1.dl_qx);
except
Application.MessageBox('动态库加载失败!','提示',64);
exit;
end;
end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
dl_xm:='123';
dl_qx:='234';
joinstr:='345';
end;

end.

dll如下:
type
Tkcsh_tj = class(TForm)
private
dl_xm,joinstr,dl_qx:string;
{ Private declarations }
public
{ Public declarations }
end;

var
kcsh_tj:Tkcsh_tj;
procedure kc_create;
procedure kc_free;
procedure kc_tj(dl_xm:string;joinstr:string;dl_qx:string);stdcall;
implementation

{$R *.dfm}
procedure kc_create;
begin
kcsh_tj:=Tkcsh_tj.Create(Application.MainForm);
end;
procedure kc_free;
begin
if Assigned(kcsh_tj) then kcsh_tj.Free;
end;
procedure kc_tj(dl_xm,joinstr,dl_qx:string);stdcall;
begin
try
kc_create;
kcsh_tj.dl_xm:=dl_xm;
kcsh_tj.joinstr:=joinstr;
kcsh_tj.dl_qx:=dl_qx;
kcsh_tj.Show;
finally
kc_free;
end;
end;
end.
...全文
100 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
baoxuetianxia 2009-11-02
  • 打赏
  • 举报
回复
更贴
W9757 2009-11-02
  • 打赏
  • 举报
回复
TO:kobaer
是不是可以这样理解,就是把你的.synapp,和showform替换我的kcsh_create和kcsh_tj呀,如可能,是否可以帮我修改我的代码按你的方法?先谢了.
kobaer 2009-11-02
  • 打赏
  • 举报
回复

dll中 frmDLL dll名字
procedure SynAPP(App: THandle); stdcall;
begin
Application.Handle := App;
end;
procedure ShowForm; stdcall;
begin
try
frmDLL := TfrmDLL.Create(Application);
try
frmDLL.ShowModal;
finally
frmDLL.Free;
end;
except
on E: Exception do
MessageDlg('Error in DLLForm: ' +
E.Message, mtError, [mbOK], 0);
end;
end;



library MyFirstDLL;
uses
SysUtils,
Classes,
frm_DLL in 'frm_DLL.pas' {frmDLL};

{$R *.res}
exports
SynAPP, ShowForm;
begin
end.


SynApp(Application.Handle ); {首先必须调用这个过程,并且使用Application 的句柄作为参数}
ShowForm ;
W9757 2009-11-02
  • 打赏
  • 举报
回复
我还是希望能从我现成的代码更改成我想要的.谢谢了.......
W9757 2009-11-02
  • 打赏
  • 举报
回复
见笑了.
qq7118622 2009-10-30
  • 打赏
  • 举报
回复
不行呀,大哥.
wintergoes 2009-10-30
  • 打赏
  • 举报
回复
kcsh_tj.Parent := Application.MainForm;
未经验证,试试
qq7118622 2009-10-30
  • 打赏
  • 举报
回复
procedure kc_create;
begin
kcsh_tj:=Tkcsh_tj.Create(Application.MainForm);
end
这里写错了,是:kcsh_tj:=Tkcsh_tj.Create(Application);
bdmh 2009-10-30
  • 打赏
  • 举报
回复
W9757 2009-10-30
  • 打赏
  • 举报
回复
不行呀,大哥.

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧