Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strike>I'm assuming that the database access in a thread is of no problem for you.</strike></p> <p>For a complete example of a threaded access to a dbExpress database (including feedback to the main thread), see the examples made by <a href="https://stackoverflow.com/users/45145/marco-cantu">Marco Cantù</a> here: <a href="http://blog.marcocantu.com/blog/dbexpress_firebird_examples.html" rel="nofollow noreferrer">dbexpress_firebird_examples</a>.</p> <p>It involves putting all the database connection setup in a <code>TDataModule</code> and creating an instance of this datamodule for each threaded access.</p> <p>Anyway, to make the GUI informed about the background thread process with an animated Gif, here is an example:</p> <p><img src="https://i.stack.imgur.com/WynfG.jpg" alt="enter image description here"></p> <pre><code>unit TestAnimatedScreen; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Imaging.GIFImg, Vcl.ExtCtrls; type TMyEndNotify = procedure (value: Boolean) of object; type TMyThread = class(TThread) private fEndNotification : TMyEndNotify; procedure NotifyEndOfThread; protected procedure Execute; override; public Constructor Create(endNotification : TMyEndNotify); end; type TMainForm = class(TForm) Image1: TImage; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } FShowAnimation : Boolean; procedure SetShowAnimation(value : Boolean); public { Public declarations } property ShowAnimation : Boolean read FShowAnimation write SetShowAnimation; end; var MainForm: TMainForm; implementation {$R *.dfm} procedure TMyThread.NotifyEndOfThread; begin if Assigned(fEndNotification) then fEndNotification(False); end; constructor TMyThread.Create(endNotification: TMyEndNotify); begin Inherited Create(false); fEndNotification := endNotification; Self.FreeOnTerminate := True; // Free automatically end; procedure TMyThread.Execute; begin try {Add your database access code here} Sleep(5000); // Simulate lengthy process finally Synchronize(NotifyEndOfThread); end; end; { TMainForm } procedure TMainForm.Button1Click(Sender: TObject); begin ShowAnimation := True; TMyThread.Create(Self.SetShowAnimation); end; procedure TMainForm.SetShowAnimation(value: Boolean); begin FShowAnimation := Value; if FShowAnimation then begin {Add animation code here} Button1.Enabled := false; Button1.Caption := 'Processing, please wait ...'; (Image1.Picture.Graphic as TGIFImage).AnimateLoop := glEnabled; (Image1.Picture.Graphic as TGIFImage).Animate := true; end else begin {Stop animation} (Image1.Picture.Graphic as TGIFImage).Animate := false; Button1.Caption := 'Start lengthy process'; Button1.Enabled := True; end; end; end. </code></pre> <hr> <pre><code>object MainForm: TMainForm Left = 0 Top = 0 Caption = 'MainForm' ClientHeight = 265 ClientWidth = 236 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object Image1: TImage Left = 8 Top = 8 Width = 200 Height = 200 AutoSize = True IncrementalDisplay = True end object Button1: TButton Left = 8 Top = 224 Width = 200 Height = 25 Caption = 'Start lengthy process' TabOrder = 0 OnClick = Button1Click end end </code></pre> <p>Should you have an older Delphi version than Delphi 2007, see <a href="https://stackoverflow.com/q/9573572/576719">How to use Animated Gif in a delphi form</a> for more information about how to implement an animated GIF.</p> <p>The animated GIF I used can be found <a href="http://en.wikipedia.org/wiki/Graphics_Interchange_Format" rel="nofollow noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload