📄 jvregauto.pas
字号:
raIniStrings:
Str.WriteBool(ConcatSep(FSection, Section, cSlash), Ident, Value);
end;
DestroyFile;
end;
function TJvRegAuto.ReadFloat(const Section, Ident: string; Default: Double): Double;
begin
Result := Default;
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Result := StrToFloat(Reg.ReadString(ConcatSep(FSection, Section, cSlash), Ident, FloatToStr(Default)));
{$ENDIF VCL}
raIniFile:
Result := Ini.ReadFloat(ConcatSep(FSection, Section, cSlash), Ident, Default);
raIniStrings:
Result := Str.ReadFloat(ConcatSep(FSection, Section, cSlash), Ident, Default);
end;
DestroyFile;
end;
procedure TJvRegAuto.WriteFloat(const Section, Ident: string; Value: Double);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.WriteString(ConcatSep(FSection, Section, cSlash), Ident, FloatToStr(Value));
{$ENDIF VCL}
raIniFile:
Ini.WriteFloat(ConcatSep(FSection, Section, cSlash), Ident, Value);
raIniStrings:
Str.WriteFloat(ConcatSep(FSection, Section, cSlash), Ident, Value);
end;
DestroyFile;
end;
procedure TJvRegAuto.ReadStrings(const Section, Ident: string; Strings: TStrings);
var
S: string;
begin
S := Strings.Text;
S := ReplaceString(S, CrLf, '|');
S := ReadString(ConcatSep(FSection, Section, cSlash), Ident, S);
S := ReplaceString(S, '|', CrLf);
Strings.Text := S;
end;
procedure TJvRegAuto.WriteStrings(const Section, Ident: string; Value: TStrings);
var
S: string;
begin
S := Value.Text;
S := ReplaceString(S, CrLf, '|');
WriteString(ConcatSep(FSection, Section, cSlash), Ident, S);
end;
procedure TJvRegAuto.ReadSection(const Section: string; Ss: TStrings);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.ReadSection(ConcatSep(FSection, Section, cSlash), Ss);
{$ENDIF VCL}
raIniFile:
Ini.ReadSection(ConcatSep(FSection, Section, cSlash), Ss);
raIniStrings:
Str.ReadSection(ConcatSep(FSection, Section, cSlash), Ss);
end;
DestroyFile;
end;
procedure TJvRegAuto.ReadSectionValues(const Section: string; Ss: TStrings);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.ReadSectionValues(ConcatSep(FSection, Section, cSlash), Ss);
{$ENDIF VCL}
raIniFile:
Ini.ReadSectionValues(ConcatSep(FSection, Section, cSlash), Ss);
raIniStrings:
Str.ReadSectionValues(ConcatSep(FSection, Section, cSlash), Ss);
end;
DestroyFile;
end;
procedure TJvRegAuto.ReadWholeSection(const Section: string; Ss: TStrings);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
{ ReadWholeSection not supported for registry }
Reg.ReadSection(ConcatSep(FSection, Section, cSlash), Ss);
{$ENDIF VCL}
raIniFile:
Ini.ReadWholeSection(ConcatSep(FSection, Section, cSlash), Ss);
raIniStrings:
Str.ReadWholeSection(ConcatSep(FSection, Section, cSlash), Ss);
end;
DestroyFile;
end;
procedure TJvRegAuto.ReadSections(Ss: TStrings);
begin
CreateFile;
case FStorage of
{$IFDEF VCL}
raRegistry:
Reg.ReadSections(Ss);
{$ENDIF VCL}
raIniFile:
Ini.ReadSections(Ss);
raIniStrings:
Str.ReadSections(Ss);
end;
DestroyFile;
end;
procedure TJvRegAuto.AddNotify(ANotify: TRegAutoEvent);
var
Notify: ^TRegAutoEvent;
begin
New(Notify);
Notify^ := ANotify;
FNotifiers.Add(Notify);
end;
procedure TJvRegAuto.RemoveNotify(ANotify: TRegAutoEvent);
var
I: Integer;
Notify: ^TRegAutoEvent;
begin
for I := 0 to FNotifiers.Count - 1 do
begin
Notify := FNotifiers[I];
if (TMethod(Notify^).Code = TMethod(ANotify).Code) and
(TMethod(Notify^).Data = TMethod(ANotify).Data) then
begin
Dispose(Notify);
FNotifiers.Delete(I);
Break;
end;
end;
end;
// support for old UseReg, UseIni, UseStr properties
procedure TJvRegAuto.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineProperty('UseReg', ReadUseRegProperty, nil, False);
Filer.DefineProperty('UseIni', ReadUseIniProperty, nil, False);
Filer.DefineProperty('UseStr', ReadUseStrProperty, nil, False);
end;
procedure TJvRegAuto.ReadUseRegProperty(Reader: TReader);
begin
// ignore False values
if Reader.ReadBoolean then
UseReg := True;
end;
procedure TJvRegAuto.ReadUseIniProperty(Reader: TReader);
begin
// ignore False values
if Reader.ReadBoolean then
UseIni := True;
end;
procedure TJvRegAuto.ReadUseStrProperty(Reader: TReader);
begin
// ignore False values
if Reader.ReadBoolean then
UseStr := True;
end;
//=== TJvMyIniFile ===========================================================
procedure TJvMyIniFile.ReadWholeSection(const Section: string; Ss: TStrings);
var
TmpSS: TStringList;
TmpIniSS: TJvIniStrings;
begin
TmpSS := TStringList.Create;
try
TmpSS.LoadFromFile(FileName);
TmpIniSS := TJvIniStrings.Create(TmpSS);
try
TmpIniSS.ReadWholeSection(Section, SS);
finally
TmpIniSS.Free;
end;
finally
TmpSS.Free;
end;
end;
//=== TJvIniStrings ==========================================================
constructor TJvIniStrings.Create(AStrings: TStrings);
begin
inherited Create;
FStrings := AStrings;
end;
function TJvIniStrings.ReadString(const Section, Ident, Default: string): string;
var
I: Integer;
S: string;
P: Integer;
begin
Result := Default;
I := FStrings.IndexOf('[' + Section + ']');
if I = -1 then
Exit;
Inc(I);
while I < FStrings.Count do
begin
S := FStrings[I];
Inc(I);
if Length(S) = 0 then
Continue;
if S[1] = '[' then
Exit;
if AnsiStrLIComp(PChar(Ident), PChar(S), Length(Ident)) = 0 then
begin
P := Pos('=', S);
if P <> 0 then
Result := Copy(S, P + 1, Length(S));
Exit;
end;
end;
end;
procedure TJvIniStrings.WriteString(const Section, Ident, Value: string);
var
F: Integer;
S: string;
begin
FStrings.BeginUpdate;
F := FStrings.IndexOf('[' + Section + ']');
if F > -1 then
begin
Inc(F);
while F < FStrings.Count do
begin
S := Trim(FStrings[F]);
if ((Length(S) > 0) and (Trim(S[1]) = '[')) or (Trim(S) = '') then
begin
FStrings.Insert(F, Ident + '=' + Value);
Break;
end
else
if UpperCase(Copy(S, 1, Pos('=', S) - 1)) = UpperCase(Ident) then
begin
FStrings[F] := Ident + '=' + Value;
Break;
end;
Inc(F);
end;
if F >= FStrings.Count then
FStrings.Add(Ident + '=' + Value);
end
else
begin
FStrings.Add('');
FStrings.Add('[' + Section + ']');
FStrings.Add(Ident + '=' + Value);
end;
FStrings.EndUpdate;
end;
function TJvIniStrings.ReadInteger(const Section, Ident: string;
Default: Longint): Longint;
begin
try
Result := StrToInt(ReadString(Section, Ident, IntToStr(Default)));
except
Result := Default;
end;
end;
procedure TJvIniStrings.WriteInteger(const Section, Ident: string; Value: Longint);
begin
WriteString(Section, Ident, IntToStr(Value));
end;
function TJvIniStrings.ReadBool(const Section, Ident: string;
Default: Boolean): Boolean;
var
S: string;
begin
S := Trim(ReadString(Section, Ident, IntToStr(Integer(Default))));
Result := (S = '1') or (AnsiCompareText(S, 'on') = 0) or (AnsiCompareText(S, 'yes') = 0);
end;
procedure TJvIniStrings.WriteBool(const Section, Ident: string; Value: Boolean);
begin
WriteString(Section, Ident, IntToStr(Integer(Value)));
end;
function TJvIniStrings.ReadFloat(const Section, Ident: string; Default: Double): Double;
begin
try
Result := StrToFloat(ReadString(Section, Ident, FloatToStr(Default)));
except
Result := Default;
end;
end;
procedure TJvIniStrings.WriteFloat(const Section, Ident: string; Value: Double);
begin
WriteString(Section, Ident, FloatToStr(Value));
end;
function TJvIniStrings.ReadSection(const Section: string; Ss: TStrings): Boolean;
var
F: Integer;
S: string;
procedure ReadSection1;
begin
Inc(F);
while F < FStrings.Count do
begin
S := FStrings[F];
if (Length(S) > 0) and (Trim(S[1]) = '[') then
Break;
if Trim(S) <> '' then
Ss.Add(S);
Inc(F);
end;
end;
begin
Ss.BeginUpdate;
try
Ss.Clear;
F := FStrings.IndexOf('[' + Section + ']');
Result := F > -1;
if Result then
begin
ReadSection1;
while F < FStrings.Count do
begin
S := Trim(FStrings[F]);
if S = '[' + Section + ']' then
ReadSection1
else
Inc(F);
end;
end;
finally
Ss.EndUpdate;
end;
end;
procedure TJvIniStrings.ReadSections(Ss: TStrings);
var
I: Integer;
S: string;
begin
Ss.Clear;
for I := 0 to FStrings.Count - 1 do
begin
S := Trim(FStrings[I]);
if (Length(S) > 0) and (S[1] = '[') and (S[Length(S)] = ']') then
Ss.Add(Copy(S, 2, Length(S) - 2));
end;
end;
procedure TJvIniStrings.ReadSectionValues(const Section: string; Ss: TStrings);
var
F: Integer;
S: string;
procedure ReadSection1;
begin
Inc(F);
while F < FStrings.Count do
begin
S := FStrings[F];
if (Length(S) > 0) and (Trim(S[1]) = '[') then
Break;
if Trim(S) <> '' then
Ss.Add(S);
Inc(F);
end;
end;
begin
Ss.BeginUpdate;
try
Ss.Clear;
F := FStrings.IndexOf('[' + Section + ']');
if F > -1 then
begin
ReadSection1;
while F < FStrings.Count do
begin
S := Trim(FStrings[F]);
if S = '[' + Section + ']' then
ReadSection1
else
Inc(F);
end;
end;
finally
Ss.EndUpdate;
end;
end;
procedure TJvIniStrings.ReadWholeSection(const Section: string; Ss: TStrings);
var
F: Integer;
S: string;
begin
with FStrings do
begin
F := IndexOf('[' + Section + ']');
// Result := F > -1;
if F > -1 then
begin
Ss.BeginUpdate;
try
Ss.Clear;
Inc(F);
while F < Count do
begin
S := Strings[F];
if (Length(S) > 0) and (Trim(S[1]) = '[') then
Break;
Ss.Add(S);
Inc(F);
end;
finally
Ss.EndUpdate;
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -