我在dll中写一过程,用form作参数在主程序中调用dll过程,再遍历表单上的控件完成修改或初始化表单上面的edit和按钮等操作。有什么方法可以实现呀,我用下面的方法不行。感觉在dll中不能用强制转换一样Components[i] as不行,还有别的什么方法实现没有,我在搜索了半天也没有找到解决的方法。
程序代码如下
 with tmyform do //tmyform是传递的表单参数 procedure tmset(var tmyform:tform);
  begin
  for i:= ComponentCount -1 downto 0 do  
  begin
  if (Components[i] is TAction) then  (Components[i] as TAction).Enabled:=false;
或 if (Components[i].classtype.classname='TAction') then  taction(Components[i]).enabled:=false;
  end;
  end;  
上面代码是在主程序过程中可以正常运行,然后我把它做成dll过程过就不能了。编译也不会出错,可程序运行中出现错误
1、先是(Components[i] is TAction)找不到taction
2、我把 if (Components[i].classname='TAction') then 这样后可在判断到为真,再执行下面的语句(Components[i] as TAction).Enabled:=false;就出现了"invalid class typecast"转换错误。然后我改成taction(Components[i]).enabled:=false;也是一样的