代码
1 unit Unit1;
2 interface
3 uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls;
6 type
7 TForm1 = class(TForm)
8 Button1: TButton;
9 Button2: TButton;
10 procedure Button1Click(Sender: TObject);
11 procedure Button2Click(Sender: TObject);
12 private
13 { Private declarations }
14 public
15 { Public declarations }
16 end;
17 var
18 Form1: TForm1;
19 implementation
20
21 {$R *.dfm}
22 function hq(ShowResult: Boolean): String;
23 //这是一个函数,返回应用程序文件所在目录
24 begin
25 Result := ParamStr(0);
26 Result := ExtractFilePath(Result);
27 if ShowResult then
28 ShowMessage('应用程序路径是:' + Result);
29 end;
30 procedure ShowInfo(Info: String);
31 //这是一个过程,显示信息Info
32 begin
33 ShowMessage('应用程序路径是:' + Info);
34 end;
35 procedure TForm1.Button1Click(Sender: TObject);
36 // Button1Click和下面的Button2Click都是方法,属于类TForm1
37 var
38 S: String;
39 begin
40 S := hq(False); //调用函数GetApplicationPath
41 ShowInfo(S); //调用过程ShowInfo
42 end;
43 procedure TForm1.Button2Click(Sender: TObject);
44 // 方法Button2Click和和方法Button1Click实现的功能是完全一样的
45 begin
46 hq(True);
47 end;
48 end.
2 interface
3 uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls;
6 type
7 TForm1 = class(TForm)
8 Button1: TButton;
9 Button2: TButton;
10 procedure Button1Click(Sender: TObject);
11 procedure Button2Click(Sender: TObject);
12 private
13 { Private declarations }
14 public
15 { Public declarations }
16 end;
17 var
18 Form1: TForm1;
19 implementation
20
21 {$R *.dfm}
22 function hq(ShowResult: Boolean): String;
23 //这是一个函数,返回应用程序文件所在目录
24 begin
25 Result := ParamStr(0);
26 Result := ExtractFilePath(Result);
27 if ShowResult then
28 ShowMessage('应用程序路径是:' + Result);
29 end;
30 procedure ShowInfo(Info: String);
31 //这是一个过程,显示信息Info
32 begin
33 ShowMessage('应用程序路径是:' + Info);
34 end;
35 procedure TForm1.Button1Click(Sender: TObject);
36 // Button1Click和下面的Button2Click都是方法,属于类TForm1
37 var
38 S: String;
39 begin
40 S := hq(False); //调用函数GetApplicationPath
41 ShowInfo(S); //调用过程ShowInfo
42 end;
43 procedure TForm1.Button2Click(Sender: TObject);
44 // 方法Button2Click和和方法Button1Click实现的功能是完全一样的
45 begin
46 hq(True);
47 end;
48 end.