procedure SaveDataToIni(const S, IniFileName, IniSection: String);
var
sHex: String;
I, M, N, X, Y: Integer;
procedure AddChar(D: Integer);
begin
Inc(N);
if D < 10 then
sHex[N]:= Chr(D + Ord('0'))
else
begin
Dec(D, 10);
sHex[N]:= Chr(D + Ord('A'));
end;
end;
begin
SetLength(sHex, 131);
M:= 0;
repeat
N:= 2;
for I:= 1 to 64 do
begin
Inc(M);
if M > Length(S) then
Break;
X:= Ord(S[M]);
AddChar(X div 16);
AddChar(X mod 16);
end;
Inc(N);
sHex[N]:= #0;
N:= M div 64;
sHex[1]:= Chr(N + Ord('A'));
sHex[2]:= #0;
WritePrivateProfileString(PChar(IniSection), @sHex[1], @sHex[3], PChar(IniFileName));
until M >= Length(S);
Str(Length(S), sHex);
WritePrivateProfileString(PChar(IniSection), 'DataSize', PChar(sHex), PChar(IniFileName));
end;
function GetDataFromIni(const IniFileName, IniSection: String): String;
var
HexChar: String[16];
Id: String[2];
I, M, N, T, X, DataSize: Integer;
begin
DataSize:= GetPrivateProfileInt(PChar(IniSection), 'DataSize', 0, PChar(IniFileName));
if DataSize = 0 then
Exit;
SetLength(Result, DataSize + 256);
HexChar[0]:= Chr(16);
for I:= 0 to 9 do
HexChar[I+1]:= Chr(I + Ord('0');
for I:= 10 to 15 do
HexChar[I+1]:= Chr(I + Ord('A');
Id:= 'A'#0;
M:= 1;
repeat
N:= GetPrivateProfileString(PChar(IniSection), @Id[1], '', @Result[M], PChar(IniFileName)) div 2;
for I:= 0 to N - 1 do
begin
T:= M + I + I;
X:= Pos(Result[T], HexChar) * 256 + Pos(Result[T+1], HexChar);
Result[M+I]:= Chr(X);
end;
Inc(M, N);
Id[1]:= Succ(Id[1]);
until M > DataSize;
SetLength(Result, DataSize);
end;