主程序EXE为何得到某个DLL里所有窗体的名称为空?附代码 ( 积分: 40 )

  • 主题发起人 wangchw0001
  • 开始时间
W

wangchw0001

Unregistered / Unconfirmed
GUEST, unregistred user!
dll代码:<br>function&nbsp;GetAllForm(lst1&nbsp;:&nbsp;TListBox)&nbsp;:&nbsp;Boolean;<br>var<br>&nbsp;&nbsp;i&nbsp;:&nbsp;Integer;<br>begin<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;true;<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i:=0&nbsp;to&nbsp;Application.ComponentCount-1&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(Application.Components&nbsp;is&nbsp;TForm)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lst1.Items.Add(Application.Components.Name)<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;except<br>&nbsp;&nbsp;&nbsp;&nbsp;Result&nbsp;:=&nbsp;False;<br>&nbsp;&nbsp;end;<br>end;<br><br>exports<br>&nbsp;&nbsp;GetAllForm;<br><br>begin<br>end.<br><br>主程序调用的代码:<br>unit&nbsp;uMain;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;StdCtrls,&nbsp;Buttons;<br><br>type<br>&nbsp;&nbsp;AllDllForm&nbsp;=&nbsp;function(lst1&nbsp;:&nbsp;TListBox)&nbsp;:&nbsp;Boolean;<br>&nbsp;&nbsp;TfrmMain&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;lst1:&nbsp;TListBox;<br>&nbsp;&nbsp;&nbsp;&nbsp;btn1:&nbsp;TBitBtn;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;btn1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;frmMain:&nbsp;TfrmMain;<br><br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>procedure&nbsp;TfrmMain.btn1Click(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;DLLHandle1:&nbsp;THandle;<br>&nbsp;&nbsp;DLLSub1:&nbsp;AllDllForm;<br>begin<br>&nbsp;&nbsp;DLLHandle1&nbsp;:=&nbsp;LoadLibrary('prjDLL.dll');<br>&nbsp;&nbsp;if&nbsp;DLLHandle1&nbsp;&lt;&gt;&nbsp;0&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;@DLLSub1&nbsp;:=&nbsp;GetProcAddress(DLLHandle1,&nbsp;'GetAllForm');<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;Assigned(DLLSub1)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;DLLSub1(lst1)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShowMessage('');<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end;<br>end;<br><br>end.
 
关注下...................
 
独立的DLL程序,这Application当然是空的。<br>必须要将主程序EXE里的Application传到DLL里才会有呀。
 
下面是dll里的窗体上的一个按钮,则能得到dll里所有的窗体.怎么那样的写我用主程序调用就得不到了呢<br>procedure&nbsp;TfrmMain.btn1Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i:=0&nbsp;to&nbsp;Application.ComponentCount-1&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(Application.Components&nbsp;is&nbsp;TForm)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lst1.Items.Add(Application.Components.Name)<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;
 
关注中<br>觉得bbscom说的很有道理
 
顶部