[Delphi] Weird output from richedit

sitnet

Senior Member
Joined
Apr 4, 2008
Messages
886
Reaction score
34
Hey guys :)

So this is the code:

Code:
procedure TForm1.btnWriteClick(Sender: TObject);
var
textfile1 : textfile;

begin
AssignFile(textfile1, edtReadFile.text + '.txt');
reset(textfile1);

If FileExists(edtReadFile.text + '.txt')  THEN
begin
 RichEdit.Lines.SaveToFile(edtReadFile.text + '.txt');
 closefile(textfile1);
end

else

begin
 ShowMessage('file not found');;
 exit;
end;

end;

All it does is save the lines from a richedit to a text file once the button is click. My problem is that say I type "Hello World" into the richedit and save it to the text file, the contents of the textfile looks like this:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}{\f1\fnil MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs16 hello
\par world\f1
\par }

Why is this?

The other thing is that as soon as Eset Smart Security is running it won't write to the text file, saying that it is being used by another process!
 
Try to remove the read only from the text file. Only had delphi experience on high school so I won't know that much.

Or the contents of the textfile could be encrypted to prevent theft or something. Who knows.
 
Why not store the lines of the richedit in a variable and then write that to the text file? My experience is also only from high school, so I dont know if that will work.
 
its because you are saving it as a .txt file. rich edits save all the formatting- fonts, bold etc. if you save it as a .doc and open it in word or wordpad you will see that it works fine

you also dont need all that other code, save to file will automatically create the file for you if it doesnt exist, and if it does, it will overwrite it.

try this:

procedure TForm1.btnWriteClick(Sender: TObject);
begin
RichEdit.Lines.SaveToFile(edtReadFile.text + '.doc');
end;
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X