最近做个分部与总部之间互相数据交换的程序,要求分部客户端连接到总部服务端后,根据每个客户端执行SQL上的特定过程,
但是每次执行完自定义的Create方法后就不执行Execute了,请问各位高手有什么办法可以解决这个问题,我的代码如下:
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
List :TStrings;
i,j :integer;
begin
  with AThread.Connection do
  begin
    List := TStringList.Create;
    AThread.Connection.ReadStrings(List);
    if List.Count>0 then
    begin
      with ListView1.Items.Add do
      begin
        i := AThread.ThreadID;
        j := ListView1.Items.Count;
        ListView1.Items[j-1].Caption := InttoStr(i);
        ListView1.Items[j-1].SubItems.Add(DateTimeToStr(Now));
        ListView1.Items[j-1].SubItems.Add(List.Strings[0]);
        ListView1.Items[j-1].SubItems.Add(List.Strings[1]);
        ListView1.Items[j-1].SubItems.Add(AThread.Connection.Socket.Binding.PeerIP);
        ListView1.Items[j-1].SubItems.Add(List.Strings[2]);
      end;
      if List.Strings[2]='FTP已连接' then
      begin
        ADOQuery1.SQL.Clear;
        ADOQuery1.SQL.Add('select * from remxls where fdbs='+''''+List.Strings[0]+'''');
        TSQLThread.Create(ADOQuery1,TMemo1);
      end;
    end;
  end;
end;
自定义线程如下:
unit Unit2;interfaceuses
  Classes, ADODB, Dialogs, SysUtils, RzStatus, RzPanel;type
  TSQLThread = class(TThread)
  private
    MyQuery :TADOQuery;
    MyStatusBar :TMemo;
    { Private declarations }
  protected
    procedure Execute; override;
  public
    RecCount :integer;
    constructor Create(ADOQuery: TADOQuery; StatusBar: TMemo);virtual;
  end;implementationuses Unit1;{ 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 TSQLThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }{ TSQLThread }constructor TSQLThread.Create(ADOQuery: TADOQuery; StatusBar: TMemo);
begin
  inherited Create(False);
  MyStatusBar := StatusBar;
  MyQuery := ADOQuery;
  MyQuery.Close;
  FreeOnTerminate := True;
end;procedure TSQLThread.Execute;
begin
  MyQuery.Open;
  { Place thread code here }
end;end.

解决方案 »

  1.   

    MyQuery :TADOQuery; 放在线程里面创建,
    从外面只传SQL语句
      

  2.   

    { 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 TSQLThread.UpdateCaption; 
        begin 
          Form1.Caption := 'Updated in a thread'; 
        end; }
    注意看你自己写的这段话。