Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > Apps

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 10-22-2012, 07:07 AM
delphinn delphinn is offline
Member
 
Join Date: Oct 2012
Posts: 80
Default *.rtf and TReachEdit

Code:
procedure tform1.AppendToRichEdit(const source, destination : TRichEdit) ;
 var
   rtfStream: TEditStream;
   sourceStream : TMemoryStream;
 
   function EditStreamReader(
     dwCookie: DWORD;
     pBuff: Pointer;
     cb: LongInt;
     pcb: PLongInt): DWORD; stdcall;
   begin
     result := $0000;
     try
       pcb^ := TStream(dwCookie).Read(pBuff^, cb) ;
     except
       result := $FFFF;
     end;
   end;
 
 begin
   destination.Lines.BeginUpdate;
   sourceStream := TMemoryStream.Create;
   try
     source.Lines.SaveToStream(sourceStream) ;
     sourceStream.Position := 0;
 
     destination.MaxLength := destination.MaxLength + sourceStream.Size;
 
     rtfStream.dwCookie := DWORD(sourceStream) ;
     rtfStream.dwError := $0000;
     rtfStream.pfnCallback := @EditStreamReader;
     destination.Perform(
       EM_STREAMIN,
       SFF_SELECTION or SF_RTF or SFF_PLAINRTF, LPARAM(@rtfStream)
     ) ;
     if rtfStream.dwError <> $0000 then
       raise Exception.Create('Error appending RTF data.') ;
   finally
     sourceStream.Free;
     destination.Lines.EndUpdate;
   end;
 end;
 
 
procedure TForm1.FormCreate(Sender: TObject);
var
  S: TFileStream;
begin
   S := TFileStream.Create ('c:\test.rtf',  fmOpenReadwrite);
   try
     richedit2.Lines.loadfromStream (S);
    finally
      S.Free;
    end;
end;
 
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  S: TFileStream;
begin
    RichEdit2.SelLength := 0;
  RichEdit2.SelStart := Length(  RichEdit2.Lines.Text);
  if   RichEdit2.CaretPos.X > 1 then
  begin
     RichEdit2.Lines.Append('');
     RichEdit2.SelLength := 0;
     RichEdit2.SelStart := Length(  RichEdit2.Lines.Text);
  end;
richedit2.SetFocus;
form1.AppendToRichEdit(richedit1,richedit2);
richedit1.Clear;
 
 S := TFileStream.Create ('c:\test.rtf', fmOpenReadwrite);
    try
     richedit2.Lines.savetoStream (S);
    finally
      S.Free;
    end;
end;

My app is to work with text in TRichEdit. The changes are stored in *.rtf.

At on formcreate event text are loaded from *.rtf into RichEdit2.Then I add text from keyboard into RE1. On formClose event the text from RE1 is appended to RE2. And then all is saved to *.rtf.

Problem:
I can do it (red text) some times but then i get erorr (exception):
'Error appending RTF data.'

Can You find out what is the problem, pleas?

Last edited by delphinn; 10-22-2012 at 08:03 AM.
Reply With Quote
  #2  
Old 10-22-2012, 08:19 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default

That's an error that you raise yourself.
You swallow the exception there, at least provide the original error code
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:55 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.