Registriert seit: 1. Feb 2018
3.691 Beiträge
Delphi 11 Alexandria
|
AW: Memo Drucken
31. Aug 2018, 09:03
Wie wäre es hiermit?
uses Printers;
Delphi-Quellcode:
procedure PrintStrings(Strings: TStrings);
var
Prn: TextFile;
i: word;
begin
AssignPrn(Prn);
try
Rewrite(Prn);
try
for i := 0 to Strings.Count - 1 do
writeln(Prn, Strings.Strings[i]);
finally
CloseFile(Prn);
end;
except
on EInOutError do
MessageDlg('Drucker nicht bereit.', mtError, [mbOk], 0);
end;
end;
so in etwa Aufrufen:
PrintStrings(Memo1.Lines);
Oder so:
Delphi-Quellcode:
// pack einen TPrintDialog und TButton auf Form
// hier wird Memo1 Font auch berücksichtigt, falls das eine Rolle spielt
procedure TForm1.Button1Click(Sender: TObject);
var
MemoOutput: TextFile;
I: LongInt;
begin
If PrintDialog1.Execute then
begin
AssignPrn(MemoOutput); //assigns a text-file variable to the printer.
try
Rewrite(MemoOutput); //creates a new file and opens it
try
Printer.Canvas.Font := Memo1.Font; //Sets Font to Printer
For I := 0 to Memo1.Lines.Count - 1 do
WriteLn(MemoOutput, Memo1.Lines[I]); //puts it to the Printer Canvas
finally
CloseFile(MemoOutput); //terminates the association between file variable and an external disk file
end;
except
on EInOutError do
MessageDlg('Drucker nicht bereit.', mtError, [mbOk], 0);
end;
end;
end;
einen hab ich noch
Delphi-Quellcode:
procedure PrintMemo(const TheMemo: TMemo);
var
MemoOutput: TextFile;
I: LongInt;
begin
If PrintDialog1.Execute then
begin
AssignPrn(MemoOutput); //assigns a text-file variable to the printer.
try
Rewrite(MemoOutput); //creates a new file and opens it
try
Printer.Canvas.Font := TheMemo.Font; //Sets Font to Printer
For I := 0 to TheMemo.Lines.Count - 1 do
WriteLn(MemoOutput, TheMemo.Lines[I]); //puts it to the Printer Canvas
finally
CloseFile(MemoOutput); //terminates the association between file variable and an external disk file
end;
except
on EInOutError do
MessageDlg('Drucker nicht bereit.', mtError, [mbOk], 0);
end;
end;
end;
Geändert von KodeZwerg (31. Aug 2018 um 09:45 Uhr)
|
|
Zitat
|