Einzelnen Beitrag anzeigen

Satty67

Registriert seit: 24. Feb 2007
Ort: Baden
1.566 Beiträge
 
Delphi 2007 Professional
 
#5

AW: Unit IniFiles bläht Programm auf

  Alt 11. Mai 2011, 17:00
Hab's nicht gross getestet, aber...
Delphi-Quellcode:
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.
...ich poste es trotzdem.

Wenn man Read/WritePrivateProfileString selbst importiert, spart man sich auch noch uses Windows.

Geändert von Satty67 (11. Mai 2011 um 17:57 Uhr)
  Mit Zitat antworten Zitat