如标题:
基本代码代码情况:
dll文件中
procedure SheZhi(WinForm : Tform) ;
var
i : integer ;
begin
if WinForm is Tform then
begin
with WinForm as Tform do
begin
for i := 0 to componentcount - 1 do
begin
if components[i] is TControl then //*********
begin
with (components[i] as TControl) do
begin
ls_ctrName = Name ;
....//从数据库中检索是否有这个控件名字,
有,对控件的属性进行修改;
end ;
end ;
end ;
end ;
end ;
end ;
问题出现在//*********位置,不管是什么控件类型如ToolButton等,在那里都通不过。
有人遇到过这种情况吗!该如何解决! 谢谢!
基本代码代码情况:
dll文件中
procedure SheZhi(WinForm : Tform) ;
var
i : integer ;
begin
if WinForm is Tform then
begin
with WinForm as Tform do
begin
for i := 0 to componentcount - 1 do
begin
if components[i] is TControl then //*********
begin
with (components[i] as TControl) do
begin
ls_ctrName = Name ;
....//从数据库中检索是否有这个控件名字,
有,对控件的属性进行修改;
end ;
end ;
end ;
end ;
end ;
end ;
问题出现在//*********位置,不管是什么控件类型如ToolButton等,在那里都通不过。
有人遇到过这种情况吗!该如何解决! 谢谢!
解决方案 »
- 如何将这段代码delphi转换成bcb或者用delphi编译成DLL
- 简单问题,就是不知道该怎么做 [在线等。。。。]
- 请问这个是我处理内存的问题吗?很奇怪的问题!
- 如何把查询到的结果整合在一起?
- 在线求助,怎样在程序中压缩ACCESS数据库
- 删除带通符串的目录
- 急问:怎么样把从oracle查询得到的数据保存到本地的dbf文件中?
- 菜鸟问:这个系统框架该怎么搭?
- RMB求购语音聊天系统源代码定做也可以!2W以下联系
- 现在我想往word插入文档(比如表格)用com好还是DDE好?
- 太不顺利了,还是Delphi_Excel问题(而且是小问题),不知道你们为什么就碰不到?=====>
- 再问一个笨问题,别笑俺
然后后在 if Component is TControl then Var
Component : TComponent;我这样没问题的,当然了,我不是在dll中的,你试一下看看
不在dll中,我测试也是可以通过的!
你的方法我也试过了,结果是一样的,没有变化,还是if判断的那句通不过
再到dll中找到该输出函数的地址,调用就可以了!********************************************************************
* Know Something About Everything, And Everything About Something!
********************************************************************
library Dll;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
ShareMem,
SysUtils,
Classes,
Forms,
About in 'About.pas' {frmAbout};{$R *.res}function ShowAbout(hdle: THandle): Boolean;
begin
Application.Handle := hdle;
with TfrmAbout.Create(Application) do
try
ShowModal;
finally
Free;
end;
end;exports
ShowAbout;begin
Sleep(1000);
end.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
procedure TfrmAbout.Button1Click(Sender: TObject);
var
i: Integer;
sFileName: String;
dllModule: THandle;
ShowStatusInfo: function(AStatusInfo: String): String; stdcall;
begin
sFileName := ExtractFileName(Application.ExeName);
dllModule := GetModuleHandle(Pchar(sFileName));
if dllModule = 0 then Exit; //取函数
ShowStatusInfo := GetProcAddress(dllModule, PChar('ShowStatusInfo'));
if not Assigned(ShowStatusInfo) then Exit; //执行函数
for i := 0 to 100 do
begin
Sleep(100);
ShowStatusInfo(IntToStr(i));
Application.ProcessMessages;
end;
end;********************************************************************
* Know Something About Everything, And Everything About Something!
********************************************************************
function ShowStatusInfo(AStatusInfo: String): String; stdcall;exports
ShowStatusInfo;
function ShowStatusInfo(AStatusInfo: String): String;
begin
if not Assigned(Form1) then Exit;
Form1.stbMain.SimpleText := AStatusInfo;
end;********************************************************************
* Know Something About Everything, And Everything About Something!
********************************************************************
如果我是在exe中写的话,就不需要在dll中调用了!直接使用不是更好吗!
* Know Something About Everything, And Everything About Something!
********************************************************************
* Know Something About Everything, And Everything About Something!
********************************************************************
还是需要将改变窗体控件属性的过程放到dll中,将要被控制的窗体传递到dll中,
我的Tform是通过参数型式传递进来的,如procedure SheZhi(WinForm : Tform) ;
感觉上是有点不对,但是又不知道怎么写才对。
if Ct.ClassType.ClassName='TButton' then
begin
TButton(CT).Caption := '测试d';
end;
这样的方式来吧,其实你上面判断了他是TControl以后里面还是要细分的吧,
如果要处理的控件不多的话暂时可以采用这样的方法完成工作
先谢谢你的帮助。
你说的方法我也考虑过的,但是对一个程序来说,如果用枚举的方法都列出来,只能暂时的解决以部分的情况,
但是我还是不明白的是,在dll中为什么就不认TControl,而在dll外确可以。
if components[i] is TControl then 是通不过了但是,在判断了
if components[i].classtype.classname = 'TButton' then
begin
TControl.components[i].enabled = false ; //这句是可以执行的了。先暂时这样解决吧,以后研究出根本的解决方法再贴上来。
end ;