Delphi函数声明可以写预设参数,定义的时候,可以不用写
代码如下:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; //函数声明 procedure ShowOnMemo (Msg: string; Caption: string = ‘信息‘; Separator: string = ‘: ‘); implementation {$R *.dfm} //函数定义 procedure ShowOnMemo (Msg: string; Caption: string ; Separator: string ); begin Form1.Memo1.Lines.Add(Caption + Separator + Msg); end; procedure TForm1.Button1Click(Sender: TObject); begin ShowOnMemo(‘曾经沧海难为水‘); end; end.
时间: 2024-10-14 01:36:11