📄 uinioption.pas
字号:
unit uIniOption;
interface
uses
Classes, SysUtils, IniFiles, Forms, Windows;
type
TCstSec = record
Name: string;
Key: string;
Value: Integer;
KeyValue: string;
end;
const
CstSection = '设置';
{Section: }
CstProp: array[1..5] of TCstSec = (
(Name: '补生命1'; key: '补生命1键'; value: 4000; KeyValue: '1'),
(Name: '补生命2'; key: '补生命2键'; value: 2000; KeyValue: '2'),
(Name: '补生命3'; key: '补生命3键'; value: 200; KeyValue: '关机'),
(Name: '补法术1'; key: '补法术1键'; value: 100; KeyValue: '4'),
(Name: '补法术2'; key: '补法术2键'; value: 50; KeyValue: '5'));
CstSkill: array[1..6] of TCstSec = (
(Name: '技能1'; key: '技能1键'; value: 180; KeyValue: 'F1'),
(Name: '技能2'; key: '技能2键'; value: 180; KeyValue: 'F2'),
(Name: '技能3'; key: '技能3键'; value: 180; KeyValue: 'F3'),
(Name: '技能4'; key: '技能4键'; value: 200; KeyValue: 'F4'),
(Name: '技能5'; key: '技能5键'; value: 200; KeyValue: 'F5'),
(Name: '技能6'; key: '技能6键'; value: 200; KeyValue: 'F6'));
type
TIniOptions = class(TObject)
private
{Section: }
public
procedure LoadSettings(Ini: TIniFile);
procedure SaveSettings(Ini: TIniFile);
procedure LoadFromFile(const FileName: string);
procedure SaveToFile(const FileName: string);
{Section: }
end;
var
IniOptions: TIniOptions = nil;
implementation
uses fmMain;
procedure TIniOptions.LoadSettings(Ini: TIniFile);
var
AProp: TPropType;
ASkill: TSkillType;
i: Integer;
begin
if Ini <> nil then
begin
{Section: }
AProp.Checked := False;
for i := 1 to 5 do
begin
AProp.Value := Ini.ReadInteger(CstSection, CstProp[i].Name, CstProp[i].Value);
AProp.Key := Ini.ReadString(CstSection, CstProp[i].Key, CstProp[i].KeyValue);
frmMain.Prop[i] := AProp;
end;
ASkill.Checked := False;
for i := 1 to 6 do
begin
ASkill.Value := Ini.ReadInteger(CstSection, CstSkill[i].Name, CstSkill[i].Value);
ASkill.Text := IntToStr(ASkill.Value);
ASkill.Key := Ini.ReadString(CstSection, CstSkill[i].Key, CstSkill[i].KeyValue);
ASkill.Value := 0;
frmMain.Skill[i] := ASkill;
end;
end;
end;
procedure TIniOptions.SaveSettings(Ini: TIniFile);
var
i: integer;
begin
if Ini <> nil then
begin
{Section: }
with frmMain do
begin
for i := 1 to 5 do
begin
Ini.WriteInteger(CstSection, CstProp[i].Name, Prop[i].Value);
Ini.WriteString(CstSection, CstProp[i].Key, Prop[i].Key);
end;
for i := 1 to 6 do
begin
Ini.WriteString(CstSection, CstSkill[i].Name, Skill[i].Text);
Ini.WriteString(CstSection, CstSkill[i].Key, Skill[i].Key);
end;
end;
end;
end;
procedure TIniOptions.LoadFromFile(const FileName: string);
var
Ini: TIniFile;
begin
if FileExists(FileName) then
begin
Ini := TIniFile.Create(FileName);
try
LoadSettings(Ini);
finally
Ini.Free;
end;
end;
end;
procedure TIniOptions.SaveToFile(const FileName: string);
var
Ini: TIniFile;
begin
Ini := TIniFile.Create(FileName);
try
SaveSettings(Ini);
finally
Ini.Free;
end;
end;
initialization
IniOptions := TIniOptions.Create;
finalization
IniOptions.Free;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -