Examples Delphi

PRINTING WITH DELPHI
PRINT WHOLE MEMO
procedure TForm1.PrintButtonClick(Sender: TObject);
var
Line: Integer;
PrintText: TextFile; {declares a file variable}
begin
if PrintDialog1.Execute then
begin
AssignPrn(PrintText); {assigns PrintText to the printer}
Rewrite(PrintText); {creates and opens the output file}
Printer.Canvas.Font := Memo1.Font; {assigns Font settings to the canvas}
for Line := 0 to Memo1.Lines.Count - 1 do
Writeln(PrintText, Memo1.Lines[Line]); {writes the contents of the Memo1 to the printer object}
CloseFile(PrintText); {Closes the printer variable}
end;
end;
OR PRINT SOMETHING A LINE AT A TIME
procedure TForm1.Print1Click(Sender: TObject);
var
PrintText: System.Text;
Redundant: Integer;
BlankFields: Boolean;
begin
BlankFields := CheckBlanks(Redundant);
if (BlankFields = False) then
begin
if PrintDialog1.Execute then
begin
AssignPrn(PrintText); {assigns PrintText to the printer}
Rewrite(PrintText); {creates and opens the output file}
Printer.Canvas.Font.Name := 'Times New Roman';
Printer.Canvas.Font.Size := 24;
with Form1 do
begin
{WriteLn prints a LINE, which includes CF/LF of course}
WriteLn(PrintText);
WriteLn(PrintText,' Chemotherapy Record');
Printer.Canvas.Font.Size := 18;
WriteLn(PrintText);
WriteLn(PrintText);
WriteLn(PrintText,' ',NameBox.Text,' Patient Number ',UnitNoBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,'____________________________________________________________');
WriteLn(PrintText);
WriteLn(PrintText,' ','Cycle ',CycleBox.Items[CycleBox.ItemIndex]);
WriteLn(PrintText);
WriteLn(PrintText,' ','Dose ',DoseNoBox.Items[DoseNoBox.ItemIndex]);
WriteLn(PrintText);
WriteLn(PrintText,' ','Regime ',RegimeBox.Items[RegimeBox.ItemIndex]);
WriteLn(PrintText);
WriteLn(PrintText,' ','Age ',AgeBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Height ',HeightBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Weight ',WeightBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Body Surface Area ',BSABox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Creatanine ',CreatBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Area Under Curve ',AUCBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Haemaglobin ',HaemBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','White Cells ',WCellBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Platelets ',PlateBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Date ',DateBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,' ','Dose ',DoseBox.Text);
WriteLn(PrintText);
WriteLn(PrintText,'____________________________________________________________');
end;
end; {end if}
CloseFile(PrintText);
end; {end if}
end;
procedure TForm1.PrintSetup1Click(Sender: TObject);
begin
PrinterSetUpDialog1.Execute;
end;