'working, please wait' screen with thread?

前端 未结 4 1145
离开以前
离开以前 2021-02-10 16:34

Perhaps, it is very easy for you, but I am hard working on a project (for educational purposes) that is querying adsi with TADSISearch component, for several days. I\'m trying t

相关标签:
4条回答
  • 2021-02-10 17:13

    Maybe you can try this:

    Threaded Splashscreen for Delphi
    http://cc.embarcadero.com/Item/20139

    I use this on a touchscreen/terminal application (thin client, Wifi, RemObjects, etc) and it works nice! Also got an animated gif working.

    0 讨论(0)
  • 2021-02-10 17:20

    How can the thread terminate before the search is finished? If the search is executed in the thread and you have only one instance of the thread it should work.

    0 讨论(0)
  • 2021-02-10 17:26

    The graphical user interface should be updated by the main thread. You should put your search code into a separate thread, and while the searcher thread is working, your main thread can show the animation along with "Please wait" message.

    Your searcher thread can notify the main thread when search is done by any of the available synchronization techniques. The simplest one is to define a method in your thread class which stops the animation in user interface, and pass that method to Synchronize at the end of Execute method of your searcher thread.

    Your searcher thread code will be something like this:

    type
      TMyThread = class(TThread)
      private
        procedure NotifyEndOfThread;
      protected
        procedure Execute; override;
      end;
    
    implementation
    
    uses MainFormUnit;
    
    procedure TMyThread.NotifyEndOfThread;
    begin
      MainForm.ShowAnimation := False;
    end;
    
    procedure TMyThread.Execute;
    begin
      try
        {Add your search code here}
      finally
        Synchronize(NotifyEndOfThread);
      end;
    end;
    

    And your main thread's code will be like this:

    TMainForm = class(TForm)
    ...
    private 
      FShowAnimation : Boolean;
      procedure SetShowAnimation(Value: Boolean);
    public
      property ShowAnimation : Boolean read FShowAnimation write SetShowAnimation;
    end;
    
    procedure TMainForm.SetShowAnimation(Value: Boolean);
    begin
      FShowAnimation := Value;
      if FShowAnimation then
        {Add animation code here}
      else
        {Stop animation}
    end;
    
    0 讨论(0)
  • 2021-02-10 17:27

    Can you not just do a

    f := TMyWaitForm.Create(self);
    try
       f.Show();
       ...start the TADSISearch...
    finally
       FreeAndNil(f);
    end;
    

    Putting an animated GIF on the TMyWaitForm (which displays itself) ?

    I have a progress form when building websites in my web creation program, and this works like a charm.

    You even may consider showing some state information on the wait form (if the TADSISearch component/software has a call back function or event which can be assigned).

    Displaying a running clock showing the amount of time the process is taking, is also a nice touch.

    0 讨论(0)
提交回复
热议问题