Einzelnen Beitrag anzeigen

madas

Registriert seit: 9. Aug 2007
207 Beiträge
 
#5

AW: anstelle auf Festplatte in den Arbeostspeicher schreiben

  Alt 10. Mär 2016, 13:36
versuche jetzt hier weiter zu machen ....


Delphi-Quellcode:
  TMemoryIniFile = Class(TStringList)
  private
    function getSectionIndex(aSection: String): Integer;
  public
    procedure WriteString(section: String; ident, value: String);
  End;


function TMemoryIniFile.getSectionIndex(aSection: String): Integer;
var
  i: Integer;
  SectionStr: String;
begin
  SectionStr := '[' + aSection + ']';
  i := self.IndexOf(SectionStr);
  if (i < 0) then
  begin
    self.Add(SectionStr);
  end;
  result := self.IndexOf(SectionStr);
end;

procedure TMemoryIniFile.WriteString(section, ident, value: String);
begin
  self.Insert(getSectionIndex(section), ident + '=' + value);
end;
besserer Ansatz ?
Warum nimmst Du nicht TMemIniFile (zu finden in der Unit IniFiles)? Benutzt intern auch nur ne TStringList, aber eine gehashte. Also Warum das Rad zweimal erfinden?

Delphi-Quellcode:
  TMemIniFile = class(TCustomIniFile)
  private
    FSections: TStringList;
    function AddSection(const Section: string): TStrings;
    function GetCaseSensitive: Boolean;
    procedure LoadValues;
    procedure SetCaseSensitive(Value: Boolean);
  public
    constructor Create(const FileName: string);
    destructor Destroy; override;
    procedure Clear;
    procedure DeleteKey(const Section, Ident: String); override;
    procedure EraseSection(const Section: string); override;
    procedure GetStrings(List: TStrings);
    procedure ReadSection(const Section: string; Strings: TStrings); override;
    procedure ReadSections(Strings: TStrings); override;
    procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
    function ReadString(const Section, Ident, Default: string): string; override;
    procedure Rename(const FileName: string; Reload: Boolean);
    procedure SetStrings(List: TStrings);
    procedure UpdateFile; override;
    procedure WriteString(const Section, Ident, Value: String); override;
    property CaseSensitive: Boolean read GetCaseSensitive write SetCaseSensitive;
  end;
  Mit Zitat antworten Zitat