Einzelnen Beitrag anzeigen

Benutzerbild von EccoBravo
EccoBravo

Registriert seit: 19. Okt 2004
Ort: Neuruppin
524 Beiträge
 
Delphi 2007 Architect
 
#16

Re: Problem : Schreiben eines Memo1.Text in ein IniFile

  Alt 30. Apr 2008, 14:09
Ich habs,

das Problem ist komplizierter als gedacht:

An diesem Object SatzList.Items[SatzNummer].Notiz hängen noch ein paar mehr Aufrufe als vorhin geschildert, und jedesmal vertauscht er die Zeichen.

So laufen über eine Property Notiz der Traffic mit Form1 und mit den IniFiles:

Delphi-Quellcode:
M_Notiz.Text := SatzList.Items[SatzNummer].Notiz
...
SatzList.Items[SatzNummer].Notiz := M_Notiz.Text

...

SatzList.Items[SatzNummer].Notiz:=PatIni.ReadString('bla', 'bla', EmptyString);
...
PatIni.WriteString('bla', 'bla', SatzList.Items[SatzNummer].Notiz);

Die Lösung:
Alle Zugriffe vom Form1 laufen wie bisher über die Eigenschaft Notiz
also über

SatzList.Items[SatzNummer].Notiz Für das Speichern und Schreiben der Notiz in ein IniFile habe ich eine extra Property NotizIni geschaffen

SatzList.Items[SatzNummer].NotizIni die den ganzen Verkehr mit den IniFiles abwickelt.

So kommen sich Form1-Traffic und IniFile-Traffic nicht mehr ins Gehege.

Das sieht so aus:
im Form1:

Delphi-Quellcode:
M_Notiz.Text := SatzList.Items[SatzNummer].Notiz;
...
SatzList.Items[SatzNummer].Notiz := M_Notiz.Text;

...

SatzList.Items[SatzNummer].NotizIni:=PatIni.ReadString('bla', 'bla', EmptyString);
...
PatIni.WriteString('bla', 'bla', SatzList.Items[SatzNummer].NotizIni);
und in der Klasse TSatz ist es wie folgt hinterlegt:

Delphi-Quellcode:
type
    TSatz = class(TObject)
    private
        ...
        FNotiz: string;
        ...
        ...
        function GetNotiz: string;
        function GetNotizIni: string;
        ...
        procedure SetNotiz(const Value: string);
        procedure SetNotizIni(const Value: string);
        ...
    public
        ...
        property Notiz: string read GetNotiz write SetNotiz;
        property NotizIni: string read GetNotizIni write SetNotizIni;
        ...
    end;

implementation

uses EB_Pat_Foto_U, controls;

...

function TSatz.GetNotiz: string;
begin
    result := FNotiz;
end;

function TSatz.GetNotizIni: string;
begin
    result := FNotizIni;
end;

...

procedure TSatz.SetNotiz(const Value: string);
begin
    FNotiz := value;
    FNotizIni := StringReplace(Value, #13 + #10,'##', [rfReplaceAll]);
end;

procedure TSatz.SetNotizIni(const Value: string);
begin
    FNotizIni := value;
    FNotiz := StringReplace(Value, '##', #13 + #10, [rfReplaceAll]);
end;
...

end.
Also vielen Dank fürs Mitdenken!

Fazit ist:
hat man mit einer Property einer Klasse unterschiedlichen Traffic-Bereiche (unterschiedliche Aufgaben) zu versorgen (dann ist es wohl auch nicht mehr eine Property), dann wäre es besser, diese Property in verschiedene Properties aufzuspalten, also für jede Aufgabe eine Property bereitzulegen.
Sicherlich eine Binsenweisheit, aber ich bin stolz, selbst drauf gekommen zu sein.

Also nochmals Danke
E. B.
Wahre Aussage :=
Katzen, die bellen sind keine Kaninchen.

Der Kreisverkehr ist eine spezielle Form der Einbahnstraße
  Mit Zitat antworten Zitat