📄 jvregauto.pas
字号:
tkFloat:
if FLoaded then
Result := GetFloatProp(Obj, PropInf);
end;
end;
procedure TJvRegAuto.SetFloatPrp(Value: Extended);
begin
case PropTyp of
tkFloat:
if FLoaded then
SetFloatProp(Obj, PropInf, Value);
end;
end;
procedure TJvRegAuto.Save;
procedure SaveOrdPrp;
var
Value: Longint;
begin
Value := GetOrdPrp;
WriteInteger(CurSection, CurKey, Value);
end;
procedure SaveFloatPrp;
var
Value: Extended;
begin
Value := GetFloatPrp;
WriteFloat(CurSection, CurKey, Value);
end;
procedure SaveStrPrp;
var
Value: string;
begin
Value := GetStrPrp;
WriteString(CurSection, CurKey, Value);
end;
var
I: Integer;
begin
for I := 0 to FNotifiers.Count - 1 do
TRegAutoEvent(FNotifiers[I]^)(Self, roBeforeSave);
if Assigned(FBeforeSave) then
FBeforeSave(Self);
try
for I := 0 to FProps.Count - 1 do
begin
LoadPropInf(FProps[I]);
if not FLoaded then
Continue;
GenerateRegistryName;
case PropTyp of
tkInteger, tkChar, tkWChar, tkEnumeration:
SaveOrdPrp;
tkFloat:
SaveFloatPrp;
tkString, tkLString , tkWString :
SaveStrPrp;
end;
end;
{$IFDEF VCL}
if SaveWindowPlace then
SaveWindowPlacement;
{$ENDIF VCL}
except
raise EJvRegAutoError.Create('Could not save property ' + ObjProp);
end;
if Assigned(FAfterSave) then
FAfterSave(Self);
for I := 0 to FNotifiers.Count - 1 do
TRegAutoEvent(FNotifiers[I]^)(Self, roAfterSave);
end;
procedure TJvRegAuto.Load;
var
I: Integer;
procedure LoadOrdPrp;
var
Value: Longint;
begin
Value := GetOrdPrp;
Value := ReadInteger(CurSection, CurKey, Value);
SetOrdPrp(Value);
end;
procedure LoadFloatPrp;
var
Value: Extended;
begin
Value := GetFloatPrp;
Value := ReadFloat(CurSection, CurKey, Value);
SetFloatPrp(Value);
end;
procedure LoadStrPrp;
var
Value: string;
begin
Value := GetStrPrp;
Value := ReadString(CurSection, CurKey, Value);
SetStrPrp(Value);
end;
begin
for I := 0 to FNotifiers.Count - 1 do
TRegAutoEvent(FNotifiers[I]^)(Self, roBeforeLoad);
if Assigned(FBeforeLoad) then
FBeforeLoad(Self);
try
{$IFDEF VCL}
if SaveWindowPlace then
LoadWindowPlacement;
{$ENDIF VCL}
for I := 0 to FProps.Count - 1 do
begin
LoadPropInf(FProps[I]);
if not FLoaded then
Continue;
GenerateRegistryName;
case PropTyp of
tkInteger, tkChar, tkWChar, tkEnumeration:
LoadOrdPrp;
tkFloat:
LoadFloatPrp;
tkString, tkLString , tkWString :
LoadStrPrp;
end;
end;
except
on E: Exception do
raise EJvRegAutoError.Create('Could not load property: ' + E.Message);
end;
if Assigned(FAfterLoad) then
FAfterLoad(Self);
for I := 0 to FNotifiers.Count - 1 do
TRegAutoEvent(FNotifiers[I]^)(Self, roAfterLoad);
end;
{$IFDEF VCL}
procedure TJvRegAuto.LoadWindowPlacement;
var
W: TWINDOWPLACEMENT;
Form: TForm;
const
Vis: array [Boolean] of Integer =
(SW_HIDE, SW_SHOW);
begin
Form := Owner as TForm;
W.length := SizeOf(TWINDOWPLACEMENT);
GetWindowPlacement(Form.Handle, @W);
W.showCmd := Vis[Form.Visible];
GenerateRegistryName;
with W.rcNormalPosition do
begin
Left := ReadInteger(CurSection, '.Left', Form.Left);
Top := ReadInteger(CurSection, '.Top', Form.Top);
if Form.BorderStyle in [bsSizeable, bsSizeToolWin] then
begin
Right := ReadInteger(CurSection, '.Right', Right);
Bottom := ReadInteger(CurSection, '.Bottom', Bottom);
end
else
begin
Right := Left + Form.Width;
Bottom := Top + Form.Height;
end;
end;
SetWindowPlacement(Form.Handle, @W);
Form.WindowState := TWindowState(ReadInteger(CurSection, '.WindowState', Integer(Form.WindowState)));
end;
procedure TJvRegAuto.SaveWindowPlacement;
var
W: TWINDOWPLACEMENT;
Form: TForm;
begin
Form := Owner as TForm;
W.length := SizeOf(TWINDOWPLACEMENT);
GetWindowPlacement(Form.Handle, @W);
GenerateRegistryName;
with W.rcNormalPosition do
begin
WriteInteger(CurSection, '.Left', Left);
WriteInteger(CurSection, '.Top', Top);
WriteInteger(CurSection, '.Right', Right);
WriteInteger(CurSection, '.Bottom', Bottom);
end;
WriteInteger(CurSection, '.WindowState', Integer(Form.WindowState));
end;
{$ENDIF VCL}
procedure TJvRegAuto.SetFProps(lProps: TStrings);
begin
FProps.Assign(lProps);
end;
{$IFDEF VCL}
function TJvRegAuto.ReadRootString(const Section, Ident, Default: string): string;
var
RegIni1: TRegIniFile;
begin
RegIni1 := TRegIniFile.Create('');
Result := RegIni1.ReadString(Section, Ident, Default);
RegIni1.Free;
end;
function TJvRegAuto.ReadRootInteger(const Section, Ident: string; Default: Longint): Longint;
var
RegIni1: TRegIniFile;
begin
RegIni1 := TRegIniFile.Create('');
Result := RegIni1.ReadInteger(Section, Ident, Default);
RegIni1.Free;
end;
procedure TJvRegAuto.WriteRootString(const Section, Ident, Value: string);
var
RegIni1: TRegIniFile;
begin
RegIni1 := TRegIniFile.Create('');
RegIni1.WriteString(Section, Ident, Value);
RegIni1.Free;
end;
procedure TJvRegAuto.WriteRootInteger(const Section, Ident: string; Value: Longint);
var
RegIni1: TRegIniFile;
begin
RegIni1 := TRegIniFile.Create('');
RegIni1.WriteInteger(Section, Ident, Value);
RegIni1.Free;
end;
procedure TJvRegAuto.SetSaveWindowPlace(F: Boolean);
begin
if Owner is TWinControl then
FSaveWindowPlace := F;
end;
{$ENDIF VCL}
procedure TJvRegAuto.SetIniStrings(AIniStrings: TStrings);
begin
IniStrings.Assign(AIniStrings);
end;
function TJvRegAuto.GetUse(Index: TStorageMedia): Boolean;
begin
Result := FStorage = Index;
end;
procedure TJvRegAuto.SetUse(Index: TStorageMedia; Value: Boolean);
begin
FStorage := Index;
end;
function TJvRegAuto.GetFullIniFileName: string;
begin
Result := ReplaceString(FIniFile, '$HOME', GetUserHome);
// make path relative to executable
{$IFDEF MSWINDOWS}
if not ((Length(Result) > 2) and (Result[2] = ':')) then
Result := ExtractFilePath(Application.ExeName) + Result;
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
if not ((Length(Result) > 0) and (Result[1] = '/')) then
Result := ExtractFilePath(Application.ExeName) + Result;
{$ENDIF LINUX}
end;
procedure TJvRegAuto.CreateFile;
begin
OldIniFile := FIniFile;
{$IFDEF VCL}
OldRegPath := FRegPath;
{$ENDIF VCL}
if FGlobalSettings then
begin
if GlobalIniFile <> '' then
FIniFile := GlobalIniFile;
{$IFDEF VCL}
if GlobalRegPath <> '' then
FRegPath := GlobalRegPath;
{$ENDIF VCL}
end;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg := TRegIniFile.Create(FRegPath);
{$ENDIF VCL}
raIniFile:
Ini := TJvMyIniFile.Create(GetFullIniFileName);
raIniStrings:
Str := TJvIniStrings.Create(FIniStrings);
end;
end;
procedure TJvRegAuto.DestroyFile;
begin
{$IFDEF VCL}
Reg.Free;
Reg := nil;
{$ENDIF VCL}
{$IFDEF LINUX}
if Ini <> nil then
Ini.UpdateFile;
{$ENDIF LINUX}
Ini.Free;
Ini := nil;
Str.Free;
Str := nil;
if FGlobalSettings then
begin
FIniFile := OldIniFile;
{$IFDEF VCL}
if GlobalRegPath <> '' then
FRegPath := GlobalRegPath;
FRegPath := OldRegPath;
{$ENDIF VCL}
end;
end;
procedure TJvRegAuto.EraseSection(const Section: string);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.EraseSection(ConcatSep(FSection, Section, cSlash));
{$ENDIF VCL}
raIniFile:
Ini.EraseSection(ConcatSep(FSection, Section, cSlash));
end;
DestroyFile;
end;
procedure TJvRegAuto.DeleteKey(const Section, Ident: string);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.DeleteKey(ConcatSep(FSection, Section, cSlash), Ident);
{$ENDIF VCL}
raIniFile:
Ini.DeleteKey(ConcatSep(FSection, Section, cSlash), Ident);
end;
DestroyFile;
end;
function TJvRegAuto.ReadString(const Section, Ident, Default: string): string;
begin
Result := Default;
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Result := Reg.ReadString(ConcatSep(FSection, Section, cSlash), Ident, Default);
{$ENDIF VCL}
raIniFile:
Result := Ini.ReadString(ConcatSep(FSection, Section, cSlash), Ident, Default);
raIniStrings:
Result := Str.ReadString(ConcatSep(FSection, Section, cSlash), Ident, Default);
end;
DestroyFile;
end;
procedure TJvRegAuto.WriteString(const Section, Ident, Value: string);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.WriteString(ConcatSep(FSection, Section, cSlash), Ident, Value);
{$ENDIF VCL}
raIniFile:
Ini.WriteString(ConcatSep(FSection, Section, cSlash), Ident, Value);
raIniStrings:
Str.WriteString(ConcatSep(FSection, Section, cSlash), Ident, Value);
end;
DestroyFile;
end;
function TJvRegAuto.ReadInteger(const Section, Ident: string;
Default: Longint): Longint;
begin
Result := Default;
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Result := Reg.ReadInteger(ConcatSep(FSection, Section, cSlash), Ident, Default);
{$ENDIF VCL}
raIniFile:
Result := Ini.ReadInteger(ConcatSep(FSection, Section, cSlash), Ident, Default);
raIniStrings:
Result := Str.ReadInteger(ConcatSep(FSection, Section, cSlash), Ident, Default);
end;
DestroyFile;
end;
procedure TJvRegAuto.WriteInteger(const Section, Ident: string; Value: Longint);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.WriteInteger(ConcatSep(FSection, Section, cSlash), Ident, Value);
{$ENDIF VCL}
raIniFile:
Ini.WriteInteger(ConcatSep(FSection, Section, cSlash), Ident, Value);
raIniStrings:
Str.WriteInteger(ConcatSep(FSection, Section, cSlash), Ident, Value);
end;
DestroyFile;
end;
function TJvRegAuto.ReadBool(const Section, Ident: string;
Default: Boolean): Boolean;
begin
Result := Default;
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Result := Reg.ReadBool(ConcatSep(FSection, Section, cSlash), Ident, Default);
{$ENDIF VCL}
raIniFile:
Result := Ini.ReadBool(ConcatSep(FSection, Section, cSlash), Ident, Default);
raIniStrings:
Result := Str.ReadBool(ConcatSep(FSection, Section, cSlash), Ident, Default);
end;
DestroyFile;
end;
procedure TJvRegAuto.WriteBool(const Section, Ident: string; Value: Boolean);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.WriteBool(ConcatSep(FSection, Section, cSlash), Ident, Value);
{$ENDIF VCL}
raIniFile:
Ini.WriteBool(ConcatSep(FSection, Section, cSlash), Ident, Value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -