(Gast)
n/a Beiträge
|
AW: Unterschied TMemIniFile 10.2 Tokyo / 10.3 Rio
3. Jan 2019, 15:51
Also damit wir alle über die gleiche Problematik sprechen:
Delphi-Quellcode:
program MemIniTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.Classes,
System.SysUtils,
System.IniFiles,
System.IOUtils;
procedure CheckIniClass(AIniFactory: TFunc< string, TCustomIniFile>);
const
C_CONTENT = ' ' + //
' [S1]' + sLineBreak + //
' k1=v1' + sLineBreak + //
' [S2]' + sLineBreak + //
' k2=v2' + sLineBreak + //
' [S1]' + sLineBreak + //
' k3=v3' + sLineBreak + //
' ';
var
lIni: TCustomIniFile;
lSectionStrings, lValueStrings: TStrings;
lKeyIdx: Integer;
lSection, lKey, lValue: string;
begin
TFile.WriteAllText(' .\test.ini', C_CONTENT);
lIni := AIniFactory(' .\test.ini');
try
lValueStrings := TStringList.Create();
try
lSectionStrings := TStringList.Create();
try
lIni.ReadSections(lSectionStrings);
for lSection in lSectionStrings do
begin
Writeln(lSection, ' :');
lValueStrings.Clear();
lIni.ReadSectionValues(lSection, lValueStrings);
for lKeyIdx := 0 to lValueStrings.Count - 1 do
begin
lKey := lValueStrings.Names[lKeyIdx];
lValue := lValueStrings.ValueFromIndex[lKeyIdx];
Writeln(' - ', lKey, ' = ', lValue);
end;
end;
finally
lSectionStrings.Free();
end;
finally
lValueStrings.Free();
end;
Writeln(' <EOF>');
finally
lIni.Free();
end;
end;
procedure Main();
begin
Writeln(' TMemIniFile:');
Writeln;
CheckIniClass(
function(AFilename: string): TCustomIniFile
begin
Result := TMemIniFile.Create(AFilename);
end);
Writeln;
Writeln(' TIniFile:');
Writeln;
CheckIniClass(
function(AFilename: string): TCustomIniFile
begin
Result := TIniFile.Create(AFilename);
end);
end;
begin
try
Main();
except
on E: Exception do
Writeln(E.ClassName, ' : ', E. Message);
end;
Readln;
end.
Unter Tokyo
Code:
TMemIniFile:
S1:
- k1 = v1
S2:
- k2 = v2
S1:
- k1 = v1
<EOF>
TIniFile:
S1:
- k1 = v1
S2:
- k2 = v2
S1:
- k1 = v1
<EOF>
Unter Rio
Code:
TMemIniFile:
S1:
- k1 = v1
- k3 = v3
S2:
- k2 = v2
<EOF>
TIniFile:
S1:
- k1 = v1
S2:
- k2 = v2
S1:
- k1 = v1
<EOF>
|
|
Zitat
|