我想通过传递Tform到dll里,然后查找所有TDataSource来处理。如果在同一个工程里,没有错。但是移到dll里,代码就出错。
何解?在dll中
procedure ShowPrintForm(AOwner:TForm);StdCall;export;
var a:Integer;
begin
for a:=0 to AOwner.ComponentCount-1 do
begin
if AOwner.Components[a] is TDataSource then/////////这里希望能通过,请教。
begin
ShowMessage('为什么没有呢?');
AOwner.Components[a] as TDataSource//用as就出错
TDataSource(AOwner.Components[a])//用强制转换虽然成功,但是TDataSource没有效果
end;
if AOwner.Components[a].ClassName='TDataSource' then
begin
ShowMessage((AOwner.Components[a] as TDataSource).ClassName);//报invalid typecase 之类的话
TDataSource(AOwner.Components[a])//用强制转换虽然成功,但是TDataSource没有效果
end;
end;
end;exports
ShowPrintForm;
何解?在dll中
procedure ShowPrintForm(AOwner:TForm);StdCall;export;
var a:Integer;
begin
for a:=0 to AOwner.ComponentCount-1 do
begin
if AOwner.Components[a] is TDataSource then/////////这里希望能通过,请教。
begin
ShowMessage('为什么没有呢?');
AOwner.Components[a] as TDataSource//用as就出错
TDataSource(AOwner.Components[a])//用强制转换虽然成功,但是TDataSource没有效果
end;
if AOwner.Components[a].ClassName='TDataSource' then
begin
ShowMessage((AOwner.Components[a] as TDataSource).ClassName);//报invalid typecase 之类的话
TDataSource(AOwner.Components[a])//用强制转换虽然成功,但是TDataSource没有效果
end;
end;
end;exports
ShowPrintForm;
解决方案 »
- 怎么样禁止Twebbrowser本身的快捷键?
- 一个基础问题,大家都来看看。谢谢!
- 我的clientsocket与serversocket进行通信时Errorcode=10053?
- 一英寸等于多少个像素点?
- 求Delphi常用控件的英文缩写!
- 斑竹兄弟们一定要救命啊,QRDBRichtext里怎么老是在报表title下部分显示不了大字段的,移到上部分又行的?我快不行拉。。
- Delphi菜鸟请教大家:如何获取Memo组件的编辑内容的行号?
- 100分求自定义组件的属性编辑器的源代码
- 请问delphi6哪里有的下载。谢谢!
- 寻求delphi网站
- delphi7 将Excel中的数据导入dbgrld,在从dbgrld导入数据中.
- QuickReport设计期分页问题(没有数据源)
initialization
CoInitialize (nil);
finalization
CoUninitialize(); 楼主可以试试
//dll中
procedure test(dd:TDataSource);StdCall;export;
begin
CoInitialize(nil);
if dd is TDataSource then
ShowMessage(dd.Name)
else ShowMessage(dd.ClassName);
CoUnInitialize;
end;exports
test;//form中
procedure test(dd:TDataSource);StdCall;external testdll.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
test(DataSource1);
test(DataSource2);
end;
还是无效。
顺便我在网上查到
http://blog.csdn.net/king_xing/archive/2009/03/25/4025133.aspx
《Delphi IDE向导代码竟然有二套TDataSource的ClassType!》郁闷中。
10楼的经验……血的教训。