home *** CD-ROM | disk | FTP | other *** search
- unit UnitStartTwoThreads;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls, Grids, DBGrids, DB;
-
- type
- TFrTwoThreads = class(TForm)
- Panel1: TPanel;
- Memo1: TMemo;
- Memo2: TMemo;
- BuClose: TButton;
- BuStartTwoThreads: TButton;
- DBGrid1: TDBGrid;
- DBGrid2: TDBGrid;
- procedure BuStartTwoThreadsClick(Sender: TObject);
- procedure FormResize(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- FrTwoThreads: TFrTwoThreads;
-
- implementation
-
- uses UnitThreads, UnitDataModule;
-
- var
- Thread1,Thread2: TThreadedQuery;
-
- {$R *.DFM}
-
- procedure TFrTwoThreads.BuStartTwoThreadsClick(Sender: TObject);
- var
- Alias,UserName,Password: string;
- FirstQuery, SecondQuery: TStrings;
-
- begin
- // If Threads already exist then free
- Thread1.Free;
- Thread2.Free;
- Thread1:= nil;
- Thread2:= nil;
- MessageDlg ('About to start two threads to perform to separate queries.',
- mtInformation, [mbOK,mbCancel], 0);
- Alias:= DataModule2.Database1.AliasName;
- UserName:= DataModule2.Database1.Params.Values['USER NAME'];
- Password:= DataModule2.Database1.Params.Values['PASSWORD'];
- FirstQuery:= TStringList.Create;
- SecondQuery:= TStringList.Create;
- try
- FirstQuery.Assign(Memo1.Lines);
- SecondQuery.Assign(Memo2.Lines);
- Thread1:= TThreadedQuery.Create ('One',Alias,UserName,Password,FirstQuery,DBGrid1);
- Thread2:= TThreadedQuery.Create ('Two',Alias,UserName,Password,SecondQuery,DBGrid2);
- //Note the Thread is freed when the this form is destroyed
- finally
- FirstQuery.Free;
- SecondQuery.Free;
- end;
- end;
-
- procedure TFrTwoThreads.FormResize(Sender: TObject);
- var
- MainFormWidth,
- MainFormWidthDiv2: integer;
- begin
- MainFormWidth:= FrTwoThreads.Width;
- MainFormWidthDiv2:= MainFormWidth div 2;
- Memo1.Width:= MainFormWidthDiv2 - 20;
- Memo2.Width:= MainFormWidthDiv2 - 20;
- Memo1.Left:= 1;
- Memo2.Left:= MainFormWidthDiv2 + 10;
- DBGrid1.Width:= MainFormWidthDiv2-1;
- DBGrid1.Left:= 1;
- DBGrid2.Width:= MainFormWidthDiv2-1;
- DBGrid2.Left:= MainFormWidthDiv2+1;
- BuStartTwoThreads.Left:= Memo1.Left+20;
- BuClose.Left:= Memo2.Left+20;
- end;
-
- procedure TFrTwoThreads.FormDestroy(Sender: TObject);
- begin
- // If Threads already exist then free
- Thread1.Free;
- Thread2.Free;
- Thread1:= nil;
- Thread2:= nil;
- end;
-
- procedure TFrTwoThreads.FormCreate(Sender: TObject);
- begin
- Panel1.Caption:= '';
-
- end;
-
- end.
-