USING AUTOMATIC PRINTING IN DELPHI

USING AUTOMATIC PRINTING IN
DELPHI
It mean print without using the VCL Component like Quick report, Fast Report etc.
We will need the unit printers (printers.tpu), Delphi alredy have it, so just add in the uses section in your unit worksheet.
First we should check or detect the default printer wich attach at the system PC.
The way to detect is using the detect function listed bellow :

//printer detection
implementation
Uses printer; //tambahkan unit printers di bagian uses
Function DapetinPrinterDefault : boolean;
Begin
If (Printer.printerindex > 0) then
Result := true
Else
Result := false;
End;
Where if printing doing when after we click the button on the form so the source code will seem like :
//print data yang mau di cetak
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
//Deteksi dulu keberadaan Printer pakai fungsi yang dah di bikin di atas
if DapetinPrinterDefault = true then
begin
Printer.BeginDoc;
//print text Belajar Delphi Menyenangkan sebanyak 6 halaman
for I := 1 to 6 do
begin
//100,100 adalah point x,y dimana posisi print akan di mulai pada canvas
Printer.Canvas.TextOut(100, 100, 'Belajar Delphi Menyenangkan');
Printer.NewPage; //pindah halaman baru
end;
Printer.EndDoc;
end
else
showmessage('Ga ada Printer Yang Terpasang');
end;

At above is the listing code the way we print document using atomatic printed from Delphi.
(08/Februari/2007; 0:26)

Download PDF File

No comments: