如何在把IDTcpClient接收文件封装在DLL中??????我写一个接收文件线程封装在DLL中 可以发送字符 但IDTcpClient用ReadLn读字符 是就失败!!
 线程在EXE 中使用就没问题 ,请问该如何解决????????

解决方案 »

  1.   

    我不知道你是怎么做的,不过我这里测试了没问题UnitDll.pas:unit UnitDll;interfaceuses
      Classes, SysUtils,IdBaseComponent,
      IdComponent, IdTCPConnection, IdTCPClient;type
      TDemoThread = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      end;implementation{ Important: Methods and properties of objects in visual components can only be
      used in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure TDemoThread.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ TDemoThread }procedure TDemoThread.Execute;
    var
      idTcp : TIdTCPClient;
      s : string;
    begin
      idTcp := TIdTCPClient.Create(nil);
      if Assigned(idTcp) then
      try
        idTcp.Host := 'www.163.com';
        idTcp.Port := 80;
        idTcp.Connect();
        s := 's';
        while (not Terminated) and idTcp.Connected and (s <> '') do
        begin
          idTcp.Write('GET / '#10#13#10#13);
          s := idTcp.ReadLn;
          s := idTcp.AllData;
        end;
      finally
        FreeAndNil(idTcp);
      end;
    end;end.
    Dll.dpr: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
      SysUtils,
      Classes,
      UnitDll in 'UnitDll.pas';{$R *.res}procedure StartThread; stdcall;
    var
      DemoThread : TDemoThread;
    begin
      DemoThread := TDemoThread.Create(false);
      DemoThread.FreeOnTerminate := true;
    end;exports
      StartThread;
    begin
    end.
    调用的 exe:procedure StartThread; external 'dll.dll' name 'StartThread';procedure TForm1.Button3Click(Sender: TObject);
    begin
      StartThread;
    end;
      

  2.   

    我的问题自己解决了原来在DLL中不能用Timer 我把Timer 删  了就没问题了还是谢谢各位大哥!散分
      

  3.   

    dll 中可以用 timer 的吧。可能是你用的方法不对。