Moin litsa,
komisch, bei mir funktioniert's
Hier mal mein Test vollständig (ein leeres TRichEdit, zwei Button)
Delphi-Quellcode:
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure RichEdit1Change(Sender: TObject);
private
{ Private declarations }
FiLogCount : integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
RichEdit1.Lines.SaveToFile('c:\temp\rtf.txt');
end;
procedure TForm1.FormCreate(Sender: TObject);
var
tneSave : TNotifyEvent;
begin
if FileExists('c:\temp\rtf.txt') then begin
tneSave := RichEdit1.OnChange;
try
RichEdit1.OnChange := nil;
RichEdit1.Lines.LoadFromFile('c:\temp\rtf.txt');
finally
RichEdit1.OnChange := tneSave;
end;
end;
FiLogCount := RichEdit1.Lines.Count;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
RichEdit1.SelStart := 0;
RichEdit1.SelLength := length(RichEdit1.Lines.Text);
RichEdit1.SelAttributes.Style := [fsBold];
RichEdit1.Lines.Add('Zeile '+IntToStr(RichEdit1.Lines.Count+1));
end;
procedure TForm1.RichEdit1Change(Sender: TObject);
var
sLine : string;
fs : TFileStream;
begin
if RichEdit1.Lines.Count = 0 then exit;
if FiLogCount = RichEdit1.Lines.Count then exit;
FiLogCount := RichEdit1.Lines.Count;
fs := TFileStream.Create('c:\temp\rtf.txt',fmOpenReadWrite,fmShareDenyWrite);
try
sLine := RichEdit1.Lines[RichEdit1.Lines.Count-1]+#13#10;
fs.Position := fs.Size;
fs.Write(sLine[1],length(sLine));
finally
FreeAndNil(fs);
end;
end;
Da nicht direkt RichEdit1.Lines.SaveToFile benutzt wird, spielt es auch keine Rolle, ob PlainText := true ist.