Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.071 Beiträge
 
Delphi 12 Athens
 
#30

AW: Ini-Writes global abfangen?

  Alt 12. Apr 2017, 08:38
Dann sollte die INI das aber auch sagen, wenn sie es nicht will.

Delphi-Quellcode:
uses
  SysUtils, IniFiles;

type
  TAccessIniFile = class(TMemIniFile)
  private
    FReadOnly: Boolean;
    procedure SetReadOnly(Value: Boolean);
  public
    constructor Create(const FileName: string; ReadOnly: Boolean=False); overload;

    procedure WriteString(const Section, Ident, Value: String); override;
    procedure DeleteKey(const Section, Ident: String); override;
    procedure EraseSection(const Section: string); override;
    procedure UpdateFile; override;

    property ReadOnly: Boolean read FReadOnly write SetReadOnly;
  end;

{ TAccessIniFile }

constructor TAccessIniFile.Create(const FileName: string; ReadOnly: Boolean);
begin
  inherited Create(FileName);
  FReadOnly := ReadOnly;
end;

procedure TAccessIniFile.DeleteKey(const Section, Ident: String);
begin
  if FReadOnly then
    raise Exception.Create('ReadOnly');
  inherited;
end;

procedure TAccessIniFile.EraseSection(const Section: string);
begin
  if FReadOnly then
    raise Exception.Create('ReadOnly');
  inherited;
end;

procedure TAccessIniFile.SetReadOnly(Value: Boolean);
begin
  if not FReadOnly and (FReadOnly <> ReadOnly) then
    UpdateFile;
  FReadOnly := ReadOnly;
end;

procedure TAccessIniFile.UpdateFile;
begin
  //if csDestroying in ComponentState then
  // Exit;
  //if FReadOnly then
  // raise Exception.Create('ReadOnly');
  //inherited;

  if not FReadOnly then
    inherited;
end;

procedure TAccessIniFile.WriteString(const Section, Ident, Value: String);
begin
  if FReadOnly then
    raise Exception.Create('ReadOnly');
  inherited;
end;
Neuste Erkenntnis:
Seit Pos einen dritten Parameter hat,
wird PoSex im Delphi viel seltener praktiziert.

Geändert von himitsu (12. Apr 2017 um 08:41 Uhr)
  Mit Zitat antworten Zitat