如标题:
基本代码代码情况:
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等,在那里都通不过。
有人遇到过这种情况吗!该如何解决!  谢谢!

解决方案 »

  1.   

    Component := Components[j] as TComponent;
    然后后在 if Component is TControl then Var
      Component : TComponent;我这样没问题的,当然了,我不是在dll中的,你试一下看看
      

  2.   

    to: sywind
    不在dll中,我测试也是可以通过的!
    你的方法我也试过了,结果是一样的,没有变化,还是if判断的那句通不过
      

  3.   

    你尝试在exe文件里写个能改控件属性的通用的方法,然后exports输出。
    再到dll中找到该输出函数的地址,调用就可以了!********************************************************************
    *   Know Something About Everything, And Everything About Something! 
    ********************************************************************
      

  4.   

    dll中的代码。记得要把application的handle传进去的!
    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! 
    ********************************************************************
      

  5.   

    exe中的代码
    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! 
    ********************************************************************
      

  6.   

    to :  g961681
    如果我是在exe中写的话,就不需要在dll中调用了!直接使用不是更好吗!
      

  7.   

    那你在哪调用呢?********************************************************************
    *   Know Something About Everything, And Everything About Something! 
    ********************************************************************
      

  8.   

    你的TForm怎么传递近来呢!********************************************************************
    *   Know Something About Everything, And Everything About Something! 
    ********************************************************************
      

  9.   

    实际上我是想作一个相对通用的模块,有点像权限控制,因为这个系统包括几部分,各个部分都能通过dll文件来达到相同的效果。
    还是需要将改变窗体控件属性的过程放到dll中,将要被控制的窗体传递到dll中,
    我的Tform是通过参数型式传递进来的,如procedure SheZhi(WinForm : Tform) ;
    感觉上是有点不对,但是又不知道怎么写才对。
      

  10.   

    编译到是可以通过,不过他不认为这些东西是TControl
      

  11.   

    对,就是这些东西它不认为是TControl ,但是通过components[i].ClassType.ClassName可以看到控件的类是什么,但是到 if components[i] is TControl then 就是通不过了。
      

  12.   

    所以建议你采用
                  if Ct.ClassType.ClassName='TButton' then
                  begin
                    TButton(CT).Caption := '测试d';
                  end;
    这样的方式来吧,其实你上面判断了他是TControl以后里面还是要细分的吧,
    如果要处理的控件不多的话暂时可以采用这样的方法完成工作
      

  13.   

    to : sywin
    先谢谢你的帮助。
    你说的方法我也考虑过的,但是对一个程序来说,如果用枚举的方法都列出来,只能暂时的解决以部分的情况,
    但是我还是不明白的是,在dll中为什么就不认TControl,而在dll外确可以。
      

  14.   

    从我试验的情况看,
    if components[i] is TControl then 是通不过了但是,在判断了
    if components[i].classtype.classname = 'TButton' then  
    begin 
         TControl.components[i].enabled = false ;    //这句是可以执行的了。先暂时这样解决吧,以后研究出根本的解决方法再贴上来。
    end ;