7.1.3. Client side with threads

You can find all source files of this example in the
"\FastReport 3\Demos\ClientServer\Client\Advanced" folder.

This example shows how you can use the "TfrxReportClient" component in the threads.

Thread class:

TfrxClientTestThread = class (TThread)

protectedprocedure Execute; override;

privateCountRep: Integer;

ErrorsCount: Integer;

Log: TMemo;

ThreadID: Integer;

procedure AppendLog;

procedure FinishLog;

publicReport: TfrxReportClient;

constructor Create(C: TfrxServerConnection; RepName: String;

Id: Integer; Rep: Integer; L: TMemo);

destructor Destroy; override;

end;

Constructor of the TfrxClientTestThread class:

constructor TfrxClientTestThread.Create(C: TfrxServerConnection; RepName: String;Id: Integer; Rep: Integer; L: TMemo);

begininherited Create(True);

FreeOnTerminate := False;

ErrorsCount := 0;

ThreadId := Id;

CountRep := Rep;

Log := L;

Report := TfrxReportClient.Create(nil);

Report.EngineOptions.ReportThread := Self;

Report.Connection := C;

Report.ReportName := RepName;

Resume;

end;

The method TfrxClientTestThread.Execute sends a request to the CountRep server. All resulting information is displayed in Memo1 by the "AppendLog" and "FinishLog" methods:

procedure TfrxClientTestThread.Execute;

vari: Integer;

begininherited;

for i := 1 to CountRep do

begin
if Terminated then break;

Report.PrepareReport;

if not Terminated then

begin
Synchronize(AppendLog);

ErrorsCount := ErrorsCount + Report.Errors.Count;

end;

end;

Synchronize(FinishLog);

end;

Before starting this program, launch the server application described above (topic 7.1.1.)

On press button "Thread test" execute the code below:

procedure TMainForm.TestBtnClick(Sender: TObject);

vari, j, k: Integer;

Thread: TfrxClientTestThread;

beginfrxServerConnection1.Host := Host.Text;

frxServerConnection1.Port := StrToInt(Port.Text);

frxServerConnection1.Login := Login.Text;

frxServerConnection1.Password := Password.Text;

frxServerConnection1.Compression := Compression.Checked;

if (Length(ProxyHost.Text) > 0) then

begin
frxServerConnection1.PrxoyHost := ProxyHost.Text;

frxServerConnection1.ProxyPort := StrToInt(ProxyPort.Text);

end;

ClearThreads;

Memo1.Lines.Add('Start test');

j := StrToInt(Threads.Text);

k := StrToInt(Rep.Text);

for i := 1 to j do

begin

Thread := TfrxClientTestThread.Create(frxServerConnection1,
ReportsList[ListBox1.ItemIndex], i, k, Memo1);

ThreadList.Add(Thread);

end;

end;

| < previous page |  | main page | next page > |