Client side with threads
You can find all source files of this example in the "FastReport\Demos\ClientServer\Client\Advanced" folder.
This example shows how you can use the "TfrxReportClient" component in the threads.
Thread class:
TfrxClientTestThread = class (TThread)
protected
procedure Execute; override;
private
CountRep: Integer;
ErrorsCount: Integer;
Log: TMemo;
ThreadID: Integer;
procedure AppendLog;
procedure FinishLog;
public
Report: 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);
begin
inherited 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;
var
i: Integer;
begin
inherited;
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.
On press button "Thread test" execute the code below:
procedure TMainForm.TestBtnClick(Sender: TObject);
var
i, j, k: Integer;
Thread: TfrxClientTestThread;
begin
frxServerConnection1.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;