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;