本人最近在写一个应用程序,实现的就是多线程连接各不同服务器的数据库(当然有的服务器可能不在线),完成后在2000下能正常运行,在XP下无法正常运行。不知是何故!

解决方案 »

  1.   

    线程代码:unit untLinktoRemoteDBS;interfaceuses
      Classes,ExtCtrls,SysUtils;type
      tLinktoRemoteDBS = class(TThread)
      private
        { Private declarations }
        fdepart:integer;
      protected
        procedure Execute; override;
      public
        constructor Create(idepart:integer);
      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 LinktoRemoteDBS.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ LinktoRemoteDBS }
    uses frmmain,untpublic;procedure tLinktoRemoteDBS.Execute;
    var oImg:timage;
    begin
      with tdepartments[fdepart-1] do
        begin
          if (not adocConn.connected) and (adocConn.ConnectionString<>'') then
            begin
              try
                adocConn.open;
                showmsg('连接服务器'+trim(departName)+'成功',informationset);
              except
                on E:Exception do begin
                  showmsg('连接服务器'+trim(departName)+'出错',informationset);
                  Terminate;
                  end;
              end;
             end;
        end;end;
    constructor tLinktoRemoteDBS.Create(idepart:integer);
    begin
      fDepart:=idepart;
      inherited Create(False);
    end;end.
    调用代码:
    for i:=1 to length(tdepartments) do
    begin
      tlinktoremotedbs(i);
    end;
      

  2.   

    你给的代码不全,很乱。。你是用一个adocConn还是每个线程一个。。
    在多线程里引用外面的FORM,最好是作参数传入。