把如下代码放在dll文件
procedure TFrmReaderTable.SetObjectTextClear(SetObject:Tobject);
begin
  if SetObject is tedit then
    (SetObject as tedit).Text := '';
  if SetObject is tcombobox then
    (SetObject as tcombobox).Text := '';
end;
------------------------------------------------------------------
procedure SetObjectTextClear(SetObject:Tobject);stdcall;
begin
  if SetObject is tedit then
    (SetObject as tedit).Text := '';
  if SetObject is tcombobox then
    (SetObject as tcombobox).Text := '';
end;
exports SetObjectTextClear;
begin
end.
------------------------------------------------------------------同样可以执行,但DLL里的过程SetObjectTextClear不起作用了.
请问这是为什么啊?

解决方案 »

  1.   

    楼上:换成函数后,结果还是一样,可以执行DLL里面的方法,但
      if SetObject is tedit then
        (SetObject as tedit).Text := '';
      if SetObject is tcombobox then
        (SetObject as tcombobox).Text := '';
    这几行没有起作用.
      

  2.   

    library Project1;
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, Buttons,StdCtrls;
    procedure SetObjectTextClear(SetObject:Tobject);stdcall;
    begin
      if SetObject.ClassName='TEdit' then
        TEdit(SetObject).Text := '';
    end;
    {$R *.res}
    exports SetObjectTextClear;
    begin
    end.
    ====================================================================var
      Form1: TForm1;
    procedure SetObject(SetObject:Tobject); stdcall;
    implementation{$R *.dfm}procedure SetObject(SetObject:Tobject); external 'project1.dll' name 'SetObjectTextClear';
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      SetObject(edit1)
    end;
      

  3.   

    TO jinjazz(人雅的标记--落寞刺客):谢谢你,
    对于原来的代码
    //////////////////////
    procedure SetObjectTextClear(SetObject:Tobject);stdcall;
    begin
      if SetObject is tedit then
        begin
          (SetObject as tedit).Text := '';
        end
          else begin
            showmessage('ok');/////////判断到(SetObject is tedit)为假
          end;
    end;
    //////////////////////////
    写在程序中时(SetObject is tedit)为真,
    但写在DLL中里(SetObject is tedit)为假,
    可以说说你对这的看法吗?