Delphi使用INI保存程序配置信息,INI文件作為配置文件簡單好用,本代碼使用INI記錄上次打開窗口的時間、上次打開窗口的位置坐標以及窗口的長寬是多少,當然,INI文件的用途遠不只這些,這僅是一個初級入門的例子,代碼如下:
01
unit
Unit1;
02
interface
03
uses
04
Windows, Messages,IniFiles, SysUtils, Variants, Classes, Graphics, Controls, Forms,
05
Dialogs, StdCtrls;
06
type
07
TForm1 =
class
(TForm)
08
LabelTime: TLabel;
09
Label2: TLabel;
10
LabelLocation: TLabel;
11
Label4: TLabel;
12
LabelSize: TLabel;
13
Label6: TLabel;
14
procedure
FormClose(Sender: TObject;
var
Action: TCloseAction);
15
FormCreate(Sender: TObject);
16
private
17
{ Private declarations }
18
public
19
{ Public declarations }
20
end
;
21
22
Form1: TForm1;
23
implementation
24
{$R *.dfm}
25
//程序啟動的時候讀取相關信息
26
TForm1
.
27
28
FileName:
string
29
MyIniFile:TIniFile;
30
QuitTime:TDateTime;
31
FormLeft,FormTop,FormWidth,FormHeight:
Integer
32
begin
33
FileName:=ExtractFilePath(Paramstr(
0
))+
'MyConfig.ini'
34
if
not
FileExists(FileName)
then
35
//如果配置文件不存在則退出處理過程
36
exit;
37
MyIniFile:=TIniFile
Create(FileName);
38
try
39
QuitTime:=MyIniFile
ReadDateTime(
'程序運行情況'
,
'上次退出時間'
,Now);
40
//如果有這個值的話
41
QuitTime<>Now
42
LabelTime
Caption:=DateTimeToStr(QuitTime)
43
else
44
Caption:=
'INI文件損壞'
45
FormLeft:=MyIniFile
ReadInteger(
'窗體樣式'
'X坐標'
99999
);
46
FormTop:=MyIniFile
'Y坐標'
47
48
(FormLeft<>
)
and
(FormTop<>
49
50
Form1
Left:=FormLeft;
51
Top:=FormTop;
52
LabelLocation
'('
+IntToStr(FormLeft)+
','
+IntToStr(FormTop)+
')'
53
54
55
56
FormWidth:=MyIniFile
'窗體寬'
57
FormHeight:=MyIniFile
'窗體高'
58
59
(FormWidth<>
(FormHeight<>
60
61
Width:=FormWidth;
62
Height:=FormHeight;
63
LabelSize
+IntToStr(FormWidth)+
+IntToStr(FormHeight)+
64
65
66
67
finally
68
//確保釋放掉INI文件
69
MyIniFile
Free;
70
//End try
71
72
//程序關閉的時候記錄相關信息
73
74
75
76
77
78
79
80
81
WriteDateTime(
82
WriteInteger(
,Form1
Left);
83
Top);
84
Width);
85
Height);
86
87
88
89
90
91
TGPPen - TGPCustomLineC
IGPFontFamily 的基本使用:uses Gdi
引:開發Internet/Intranet的應用程序大約有
本來這個例子是要獲取區域的詳細信息的, 但非常