unit UMiniIni;
interface
uses
Windows;
type
TMiniIni =
class
private
FFilename :
String;
FMaxValueLength : Integer;
public
constructor Create(IniFilename :
String; MaxValueLength : Integer = 255);
procedure WriteString(Section, Key, Value :
String);
function ReadString(Section, Key,
Default :
String) :
String;
end;
implementation
{ TMiniIni }
constructor TMiniIni.Create(IniFilename:
String; MaxValueLength : Integer = 255);
begin
FFilename := IniFilename;
if (MaxValueLength > 32766)
then
FMaxValueLength := 32766
else if (MaxValueLength < 255)
then
FMaxValueLength := 255
else
FMaxValueLength := MaxValueLength;
end;
function TMiniIni.ReadString(Section, Key,
Default:
String):
String;
var
pResult : PChar;
begin
GetMem(pResult, FMaxValueLength);
GetPrivateProfileString(PChar(Section), PChar(Key), PChar(
Default),
pResult, FMaxValueLength, PChar(FFileName));
Result := pResult;
FreeMem(pResult, FMaxValueLength);
end;
procedure TMiniIni.WriteString(Section, Key, Value:
String);
var
OutString :
String;
begin
OutString := Copy(Value, 1, FMaxValueLength);
WritePrivateProfileString(PChar(Section), PChar(Key),
PChar(OutString), PChar(FFilename));
end;
end.