+ -
当前位置:首页 → 问答吧 → 同样的一个过程语句,Components[i]as从程序中移动到dll文件中出现错误

同样的一个过程语句,Components[i]as从程序中移动到dll文件中出现错误

时间:2011-11-14

来源:互联网

程序代码如下
 with tform(frmid) do //frmid是传递的表单参数
  begin
  for i:= ComponentCount -1 downto 0 do 
  begin
  if (Components[i] is TAction) then
  (Components[i] as TAction).Enabled:=false;
  end;
  end; 
下面代码是在主程序过程中可以正常运行,然后我把它做成dll过程过就不能了。编译也不会出错,可程序运行中出现错误
1、先是(Components[i] is TAction)找不到taction
2、我把 if (Components[i].classname='TAction') then 这样后,下面的(Components[i] as TAction).Enabled:=false;就出现了转换错误。

作者: gongqs   发布时间: 2011-11-14

传递的参数是怎么写的?改成var

如:procedure X(var frmid:TForm)

作者: kaikai_kk   发布时间: 2011-11-14

过程参数的地方是:procedure X(frmid:TForm) 没有var,不过有这个VAR这句跟下面有关系吗,用跟踪调试的时候Components[i].name也可以看到各个控件名称的呀。

作者: gongqs   发布时间: 2011-11-14

用if (Components[i].classtype.classname='taction')

作者: funxu   发布时间: 2011-11-14

其它的都没有问题,关键是(Components[i] as TAction).Enabled:=false这句出错了

作者: gongqs   发布时间: 2011-11-14

其它的都没有问题,就是(Components[i] as TAction).Enabled:=false这句出错了提示"invalid class typecast",因为有加if进行判断是不是这种类型,我觉得应该不是什么类型转换出错的呀。

作者: gongqs   发布时间: 2011-11-14