function
Form_iniLoad(Form: TForm; SectionName:
string
=
''
; MaxSize:
Boolean
=
False
):
Boolean
;
var
ini: TIniFile;
iniPath:
string
;
WP: TWindowPlacement;
begin
Result :=
False
;
if
SectionName =
''
then
SectionName := Form
.
Name;
iniPath := ExtractFilePath(Application
.
ExeName) + _setini;
if
FileExists(iniPath)
then
begin
ini := TiniFile
.
Create(iniPath);
try
if
ini
.
SectionExists(SectionName)
then
begin
Form
.
Position := poDesigned;
Form
.
Top := ini
.
ReadInteger( SectionName,
'Top'
,
100
);
Form
.
Left := ini
.
ReadInteger( SectionName,
'Left'
,
100
);
Form
.
Height := ini
.
ReadInteger( SectionName,
'Height'
, Form
.
Height );
Form
.
Width := ini
.
ReadInteger( SectionName,
'Width'
, Form
.
Width );
Form_TLWH_Normalize(Form);
if
ini
.
ReadBool(SectionName,
'Maximized'
,
False
)
then
Form
.
WindowState := wsMaximized;
Result :=
True
;
end
;
finally
ini
.
Free;
end
;
end
;
if
not
Result
then
begin
Form
.
Position := poScreenCenter;
Form
.
WindowState := wsNormal;
Form_TLWH_Normalize(Form);
if
MaxSize
then
begin
GetWindowPlacement(Form
.
Handle, @WP);
WP
.
rcNormalPosition
.
Top := Form
.
Top;
WP
.
rcNormalPosition
.
Left := Form
.
Left;
WP
.
rcNormalPosition
.
Bottom := Form
.
Top + Form
.
Height;
WP
.
rcNormalPosition
.
Right := Form
.
Left + Form
.
Width;
Form
.
WindowState := wsMaximized;
end
;
end
;
end
;
procedure
Form_iniSave(Form: TForm; SectionName:
string
=
''
);
var
ini : TIniFile;
d: TWindowPlacement;
begin
if
SectionName =
''
then
SectionName := Form
.
Name;
ini := TiniFile
.
Create( Path_App + _setini );
try
ini
.
WriteBool( SectionName,
'Maximized'
, Form
.
WindowState = wsMaximized );
GetWindowPlacement(Form
.
Handle, @d);
ini
.
WriteInteger( SectionName,
'Top'
, d
.
rcNormalPosition
.
Top );
ini
.
WriteInteger( SectionName,
'Left'
, d
.
rcNormalPosition
.
Left );
ini
.
WriteInteger( SectionName,
'Height'
, d
.
rcNormalPosition
.
Bottom - d
.
rcNormalPosition
.
Top );
ini
.
WriteInteger( SectionName,
'Width'
, d
.
rcNormalPosition
.
Right - d
.
rcNormalPosition
.
Left );
finally
ini
.
Free;
end
;
end
;
procedure
Form_TLWH_Normalize(Form: TForm);
begin
if
Form
.
Height > Screen
.
Height
then
Form
.
Height := Screen
.
Height;
if
Form
.
Width > Screen
.
Width
then
Form
.
Width := Screen
.
Width ;
if
Form
.
Top > Screen
.
Height - Form
.
Height
then
Form
.
Top := Screen
.
Height - Form
.
Height;
if
Form
.
Top <
0
then
Form
.
Top :=
0
;
if
Form
.
Left > Screen
.
Width - Form
.
Width
then
Form
.
Left := Screen
.
Width - Form
.
Width;
if
Form
.
Left <
0
then
Form
.
Left :=
0
;
end
;