如何插入或连接两个程序?
How insert or connect two procedures?
您好,我有一个菜单,其中有一个用于备忘录的打印部分,现在我不知道如何单击该部分以 运行 我找到的这个打印代码。
如何 link 或可能插入这部分
PrintTStrings 程序 (Lst: TStrings);
在程序菜单部分
TForm1.MenuItemPrintClick(发件人:TObject);
开始
结束;
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
end;
procedure PrintTStrings(Lst : TStrings) ;
var
I,
Line : Integer;
begin
I := 0;
Line := 0 ;
Printer.BeginDoc ;
for I := 0 to Lst.Count - 1 do begin
Printer.Canvas.TextOut(0, Line, Lst[I]);
{Font.Height is calculated as -Font.Size * 72 / Font.PixelsPerInch which returns
a negative number. So Abs() is applied to the Height to make it a non-negative
value}
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight) then
Printer.NewPage;
end;
Printer.EndDoc;
end;
您必须声明 PrintStrings
程序才能使用它。正确的方法是通过在表单声明的 private
部分中声明它来使 PrintTStrings
成为表单的方法:
type
TForm1 = class(TForm)
// Items you've dropped on the form, and methods assigned to event handlers
private
procedure PrintTStrings(Lst: TStrings);
end;
然后您可以直接从菜单项的 OnClick
事件中调用它:
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
PrintTStrings(PrinterMemo.Lines);
end;
如果由于某种原因你不能把它变成一个表单方法,你可以重新排列你的代码:
procedure PrintTStrings(Lst : TStrings) ;
var
I,
Line : Integer;
begin
I := 0;
Line := 0 ;
Printer.BeginDoc ;
for I := 0 to Lst.Count - 1 do begin
Printer.Canvas.TextOut(0, Line, Lst[I]);
{Font.Height is calculated as -Font.Size * 72 / Font.PixelsPerInch which returns
a negative number. So Abs() is applied to the Height to make it a non-negative
value}
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight) then
Printer.NewPage;
end;
Printer.EndDoc;
end;
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
PrintTStrings(PrinterMemo.Lines);
end;
您好,我有一个菜单,其中有一个用于备忘录的打印部分,现在我不知道如何单击该部分以 运行 我找到的这个打印代码。
如何 link 或可能插入这部分
PrintTStrings 程序 (Lst: TStrings);
在程序菜单部分
TForm1.MenuItemPrintClick(发件人:TObject);
开始
结束;
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
end;
procedure PrintTStrings(Lst : TStrings) ;
var
I,
Line : Integer;
begin
I := 0;
Line := 0 ;
Printer.BeginDoc ;
for I := 0 to Lst.Count - 1 do begin
Printer.Canvas.TextOut(0, Line, Lst[I]);
{Font.Height is calculated as -Font.Size * 72 / Font.PixelsPerInch which returns
a negative number. So Abs() is applied to the Height to make it a non-negative
value}
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight) then
Printer.NewPage;
end;
Printer.EndDoc;
end;
您必须声明 PrintStrings
程序才能使用它。正确的方法是通过在表单声明的 private
部分中声明它来使 PrintTStrings
成为表单的方法:
type
TForm1 = class(TForm)
// Items you've dropped on the form, and methods assigned to event handlers
private
procedure PrintTStrings(Lst: TStrings);
end;
然后您可以直接从菜单项的 OnClick
事件中调用它:
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
PrintTStrings(PrinterMemo.Lines);
end;
如果由于某种原因你不能把它变成一个表单方法,你可以重新排列你的代码:
procedure PrintTStrings(Lst : TStrings) ;
var
I,
Line : Integer;
begin
I := 0;
Line := 0 ;
Printer.BeginDoc ;
for I := 0 to Lst.Count - 1 do begin
Printer.Canvas.TextOut(0, Line, Lst[I]);
{Font.Height is calculated as -Font.Size * 72 / Font.PixelsPerInch which returns
a negative number. So Abs() is applied to the Height to make it a non-negative
value}
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight) then
Printer.NewPage;
end;
Printer.EndDoc;
end;
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
PrintTStrings(PrinterMemo.Lines);
end;