ลองศึกษาจาก TurboHOSxP
ตาม Procedure นี้ครับ
เรียกใช้แบบนี้
printreportwithparam('FORM-PASADU-FORM-1', Fperson_id,
'', '', '', '', '', '', '', '', '');
ที่มา
procedure PrintReportWithParam(ReportName: string; pr1, pr2, pr3, pr4, pr5, pr6,
pr7, pr8, pr9, pr10: string);
var
f, sf: tform;
var
i, i1, i2: integer;
s: string;
es: tstringlist;
ei: integer;
se: string;
userparam: tstringlist;
begin
if getsqldata('select count(*) as cc from reporttemplate where name="' +
reportname + '"') = 0 then
begin
showmessage('Report ' + reportname + ' Not found !!!!' + #13 +
'Please contact system administrator');
exit;
end;
if getsqldata('select count(*) as cc from reporttemplate where name = "'+
reportname+'--'+mainform.tvapi.computername+'"')>0 then
begin
reportname:=reportname+'--'+mainform.tvapi.computername;
end;
LogReportAccess(ReportName);
mainform.jvinter.pas.text := '';
{ try
if assigned(PrintStatusForm) then
begin
try
PrintStatusForm.close;
except
end;
freeandnil(PrintStatusForm);
end;
except
end; }
userparam := tstringlist.create;
try
userparam.add(pr1);
userparam.add(pr2);
userparam.add(pr3);
userparam.add(pr4);
userparam.add(pr5);
userparam.add(pr6);
userparam.add(pr7);
userparam.add(pr8);
userparam.add(pr9);
userparam.add(pr10);
userparam.savetofile(gettempdir + 'KSK-param.txt');
finally
userparam.free;
end;
frrhide := true;
//setmanoiagent('', 'print', false);
// hosxpdm.KSKDCOM.appserver.sendbroadcastnotifymessage('~Printing Report:' + reportname + ':Default Printer:Param [' + pr1 + ',' + pr2 + ',' + pr3 + ',' + pr4 + ',' + pr5 + ',' + pr6 + ',' + pr7 + ',' + pr8 + ',' + pr9 + ',' + pr10 + ']');
//disablebmessage;
{
application.createform(TPrintstatusForm, PrintStatusForm);
PrintStatusForm.FormStyle := fsstayontop;
PrintStatusForm.StickTo := mainform.Agent;
PrintStatusForm.showcaption := false;
// office97balloon.Caption:='Save Data';
PrintStatusForm.Show; }
application.processmessages;
// sf := findform(PrintStatusForm);
// tReorderstatusform(sf).pg.position := 0;
// tReorderstatusform(sf).image1.picture.assign(nil);
// tReorderstatusform(sf).fclabel1.caption := 'Please Wait Preparing Report';
application.processmessages;
{application.createform(TReportPrintForm, ReportPrintForm);
try
ReportPrintForm.formstyle := fsnormal;
ReportPrintForm
ptemrform.hnedit.text := hnedit.text;
ptemrform.showmodal;
finally
ptemrform.free;
end; }
// findshowform(TReportPrintForm, '');
application.createform(TReportPrintForm, ReportPrintForm);
application.processmessages;
// f := findform(TReportPrintForm);
with reportprintform do
begin
width := 50;
height := 30;
top := 1;
left := 1;
formstyle := fsnormal;
// windowstate := wsminimized;
application.processmessages;
preparereport(reportname);
if lastprintreport <> reportname then
ReportTemplateSave(reportname);
if vartostr(getsqldata('select script_dfm from reporttemplate where name = "' +
reportname + '"')) <> '' then
begin
reportvalue[1] := pr1;
reportvalue[2] := pr2;
reportvalue[3] := pr3;
reportvalue[4] := pr4;
reportvalue[5] := pr5;
reportvalue[6] := pr6;
reportvalue[7] := pr7;
reportvalue[8] := pr8;
reportvalue[9] := pr9;
reportvalue[10] := pr10;
mainform.RunScriptProgramEx(gettempdir + 'KSK-Script.PAS');
end else
if pos(' main', mainform.jvinter.pas.text) > 0 then
begin
reportvalue[1] := pr1;
reportvalue[2] := pr2;
reportvalue[3] := pr3;
reportvalue[4] := pr4;
reportvalue[5] := pr5;
reportvalue[6] := pr6;
reportvalue[7] := pr7;
reportvalue[8] := pr8;
reportvalue[9] := pr9;
reportvalue[10] := pr10;
mainform.jvinter.run;
end;
sqledit.Lines.LoadFromFile(gettempdir + 'KSK-Report.SQL');
for i := frrparamlist.count - 1 downto 0 do
begin
s := getcolonstring(frrparamlist, 2);
s := replacestr(s, '-', ':');
i1 := strtoint(getcolonstring(s, 1));
i2 := strtoint(getcolonstring(s, 2));
sqledit.selstart := i1;
sqledit.sellength := i2;
case i of
9: sqledit.seltext := pr10;
8: sqledit.seltext := pr9;
7: sqledit.seltext := pr8;
6: sqledit.seltext := pr7;
5: sqledit.seltext := pr6;
4: sqledit.seltext := pr5;
3: sqledit.seltext := pr4;
2: sqledit.seltext := pr3;
1: sqledit.seltext := pr2;
0: sqledit.seltext := pr1;
end;
end;
with mainform do
begin
freeandnil(tempcds);
tempcds := tclientdataset.create(hosxpdm);
// tempcds.remoteserver := hosxpdm.kskdcom;
// tempcds.providername := 'ReportProvider';
{ reportcds.close;
reportcds.datarequest(sqledit.text);
reportcds.Open; }
es := tstringlist.create;
es.assign(sqledit.lines);
if es.count > 0 then
for ei := 0 to es.count - 1 do
begin
se := trim(es[ei]);
if length(se) > 0 then
if se[length(se)] = ';' then
begin
es[ei] := ' ';
tempcds.datarequest('EXEC ' + se);
end;
end;
tempcds.data := hosxp_getdataset(es.text);
// tempcds.open;
es.free;
tempcds.SaveToFile(gettempdir + 'report.cds');
freeandnil(PrintStatusForm);
LastPrintReport := reportname;
if FUseInternalReportEngine then
begin
application.createform(TRBuilderDM, RBuilderDM);
RBuilderDM.reportcds.close;
RBuilderDM.reportcds.data := tempcds.data;
try
with RBuilderDM do
begin
reportds.dataset := RBuilderDM.reportcds;
ppreport.template.filename := gettempdir + 'KSK-Report.RTM';
ppreport.template.LoadFromFile;
ppreport.DeviceType := 'Screen';
ppreport.AllowPrintToFile := True;
ppreport.ShowPrintDialog := true;
ppreport.ModalPreview := true;
ppreport.print;
end;
finally
RBuilderDM.free;
end;
end else
begin
DLLHandle := LoadLibrary(PChar(extractfiledir(application.exename) +
'\hos_rpt.dll'));
FuncPtr := GetProcAddress(DLLHandle, 'DLLPreviewReport');
if FuncPtr <> nil then
begin
@DLLPreviewReport := FuncPtr;
DLLPreviewReport();
FuncPtr := nil;
end;
FreeLibrary(DLLHandle);
end;
hosxpdm.reportds.dataset := tempcds;
// ppreport.template.filename := gettempdir + 'KSK-Report.RTM';
// ppreport.template.LoadFromFile;
// ppreport.datapipeline := ppDBPipeline;
// TReorderStatusform(sf).close;
// if frrprintcopy > 0 then
// ppreport.printersetup.copies := frrprintcopy;
// // ppreport.print;
// ppreport.printersetup.copies := 1;
end;
//close;
end;
//end;
reportprintform.free;
//enablebmessage;
end;