Print report using fastreport4(VCL version)in BCB
Hello ,
in BCB,I create a service application MyService1 on whose event:ServiceExecute a thread is created and resume.
In the thread's cpp file ,I write the following code:
in TService1.cpp:
TThreadPrint *th;
void __fastcall TService1::ServiceExecute(TService *Sender)
{
CoInitialize(NULL) ;
while(!Terminated)
{
if(th==NULL)
{//create a thread if is null
th=new TThreadPrint(true);
th->Resume();
}
Sleep(5000);
}
CoUninitialize();
}
in TThreadPrint.cpp
//
void __fastcall TThreadPrint::Execute()
{
//---- Place thread code here ----
Synchronize(Print);
}
//
void __fastcall TThreadPrint::Print()
{
TfrxReport *frxReport1=new TfrxReport(NULL);
frxReport1->EngineOptions->EnableThreadSafe=true;
frxReport1->EngineOptions->DestroyForms=false;
frxReport1->LoadFromFile("test.fr3");
frxReport1->PrepareReport(true);
frxReport1->PrintOptions->ShowDialog=false;
frxReport1->Print();
}
//
The content of file "test.fr3" is just a string "HELLO".
When the service application MyService1 starts ,then thread TThreadprint will be created and TThreadPrint::Print method executed.
However,in the method TThreadPrint::Print(), the statement frxReport1->Print() executed and quickly finished but without any result what is expected to print the report in the physical printer but the printer does not respon.
Is there any options should be set to make the TfrxReport run effectivily in the thread in the service application.
thx.
in BCB,I create a service application MyService1 on whose event:ServiceExecute a thread is created and resume.
In the thread's cpp file ,I write the following code:
in TService1.cpp:
TThreadPrint *th;
void __fastcall TService1::ServiceExecute(TService *Sender)
{
CoInitialize(NULL) ;
while(!Terminated)
{
if(th==NULL)
{//create a thread if is null
th=new TThreadPrint(true);
th->Resume();
}
Sleep(5000);
}
CoUninitialize();
}
in TThreadPrint.cpp
//
void __fastcall TThreadPrint::Execute()
{
//---- Place thread code here ----
Synchronize(Print);
}
//
void __fastcall TThreadPrint::Print()
{
TfrxReport *frxReport1=new TfrxReport(NULL);
frxReport1->EngineOptions->EnableThreadSafe=true;
frxReport1->EngineOptions->DestroyForms=false;
frxReport1->LoadFromFile("test.fr3");
frxReport1->PrepareReport(true);
frxReport1->PrintOptions->ShowDialog=false;
frxReport1->Print();
}
//
The content of file "test.fr3" is just a string "HELLO".
When the service application MyService1 starts ,then thread TThreadprint will be created and TThreadPrint::Print method executed.
However,in the method TThreadPrint::Print(), the statement frxReport1->Print() executed and quickly finished but without any result what is expected to print the report in the physical printer but the printer does not respon.
Is there any options should be set to make the TfrxReport run effectivily in the thread in the service application.
thx.
Comments
frxReport1->Print() does not work with a TService application.
Did you find a solution yet?
yours,
Herwig