1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
Uses IniFiles; const SZ_APP_NAME = 'demo_test' ; Procedure TForm1 . GetSettings; var _MemIniU: TMemIniFile; _SettingsPath: string ; begin try _SettingsPath := GetHomePath + PathDelim + SZ_APP_NAME + PathDelim; if ForceDirectories(_SettingsPath) then begin _MemIniU := TMemIniFile . Create(ChangeFileExt(_SettingsPath, 'Settings.ini' ), TEncoding . UTF8); try if _MemIniU . ReadInteger(SZ_APP_NAME, 'WindowLeft' , - 1 ) = - 1 then Form1 . Position := poScreenCenter else begin Form1 . Left := _MemIniU . ReadInteger(SZ_APP_NAME, 'WindowLeft' , 10 ); Form1 . Top := _MemIniU . ReadInteger(SZ_APP_NAME, 'WindowTop' , 10 ); Form1 . Width := _MemIniU . ReadInteger(SZ_APP_NAME, 'WindowWidth' , 594 ); Form1 . Height := _MemIniU . ReadInteger(SZ_APP_NAME, 'WindowHeight' , 342 ); end ; Edit1 . Text := _MemIniU . ReadString(SZ_APP_NAME, 'UnicodeText' , 'ąčę' ); finally _MemIniU . Free; end ; end ; except on E: Exception do MessageDlg( PWideChar (E . Message), TMsgDlgType . mtError, [TMsgDlgBtn . mbOK], 0 ); end ; end ; Procedure TForm1 . SaveSettings; var _MemIniU: TMemIniFile; _SettingsPath: string ; begin try _SettingsPath := GetHomePath + PathDelim + SZ_APP_NAME + PathDelim; _MemIniU := TMemIniFile . Create(ChangeFileExt(_SettingsPath, 'Settings.ini' ), TEncoding . UTF8); try if Form1 . WindowState <> TWindowState . wsMaximized then begin _MemIniU . WriteInteger(SZ_APP_NAME, 'WindowLeft' , Form1 . Left); _MemIniU . WriteInteger(SZ_APP_NAME, 'WindowTop' , Form1 . Top); _MemIniU . WriteInteger(SZ_APP_NAME, 'WindowWidth' , Form1 . Width); _MemIniU . WriteInteger(SZ_APP_NAME, 'WindowHeight' , Form1 . Height); _MemIniU . WriteString(SZ_APP_NAME, 'UnicodeText' , Edit1 . Text); end ; _MemIniU . UpdateFile; finally _MemIniU . Free; end ; except on E: Exception do MessageDlg( PWideChar (E . Message), TMsgDlgType . mtError, [TMsgDlgBtn . mbOK], 0 ); end ; end ; |
https://www.cnblogs.com/starluck/p/6611550.html