Delphi : How to create and use Thread locally?

后端 未结 3 1897
既然无缘
既然无缘 2021-02-10 15:03

My database is in a VPS and I should get some query from my tables

Because of getting query from server taking long time ( depending on Internet speed ! ) , I want to us

3条回答
  •  [愿得一人]
    2021-02-10 15:28

    I think that using a thread this way isn't a good idea, but the answer is yes. You can do it.

    procedure LocalThread;
    var
      LThread: TCustomThread; //Your thread class
      LThreadResult: xxxxxxx//Your result type
    begin
      LThread := TCustomThread.Create(True);
      try
        //Assign your properties
    
        LThread.Start;
    
        //Option A: blocking
        LThread.WaitFor;
    
        //Option B: non blocking
        while not LThread.Finished do
        begin
          Sleep(xx);
          //Some progress here ??
        end;
    
        //Here query your thread for your result property
        LThreadResult := LThread.MyResultProperty;
      finally
        LThread.Free;
      end
    
      //Do next jobs with LThreadResult
    end;
    

提交回复
热议问题