Klavs
Klavs

Reputation: 47

Delphi show progress on clientdataset open

My current code

   Screen.Cursor := crSQLWait;
   ProgressDlg := TProgressDlg.Create(Application);
   try
      ProgressDlg.ProgressLabel.Caption := 'Loading data. Please wait...';
      ProgressDlg.Show;
      Application.ProcessMessages;
      if MainCDS.RemoteServer <> nil then
      begin
         MainCDS.Active := false;
         MainCDS.Active := true; 
      end;
   finally
      FreeAndNil(ProgressDlg);
      Screen.Cursor := crDefault;
   end;

How can I make my marquee progressbar on ProgressDlg move while MainCDS is opening, cause now progressbar is freezed while MainsCDS is opening. Hope You understand my problem.

Upvotes: 1

Views: 1987

Answers (1)

David Heffernan
David Heffernan

Reputation: 613511

You need to run the database access and the progress dialog in different threads. That's the only option because the databse access code is synchronous with no callbacks. Well, I'm assuming that your database layer does not offer regular callbacks that you could use to keep the UI alive. Is that so?

If you cannot put the database code in a background thread, then you are in a bind. The GUI code for the progress dialog wants to be in the main thread. If you move that to a background thread then you can't use the VCL since it is tied to the main GUI thread. So you may need to resort to raw Win32 API calls.

Upvotes: 1

Related Questions