Ver Mensaje Individual
  #7  
Antiguo 27-11-2004
johncook johncook is offline
Miembro
 
Registrado: oct 2004
Posts: 65
Reputación: 20
johncook Va por buen camino
Que tal Román. Acá te adjunto la unidad que redefiní (solo cambié el richedit por un rxrichedit) y la forma en la que la utilicé.

Código Delphi [-]
 
 unit u_sumarrtf;
 
 interface
 
 uses Windows, ComCtrls, Classes, rxriched;
 
 type
  TEditStreamCallBack = function (dwCookie: Longint; pbBuff: PByte;cb:
 Longint; var pcb: Longint): DWORD; stdcall;
 
  TEditStream = record
   dwCookie: Longint;
   dwError: Longint;
   pfnCallback: TEditStreamCallBack;
 end;
 
 procedure GetRTFSelection( aRichEdit: TRxRichEdit; intoStream:
 TStream );
 
 procedure PutRTFSelection( aRichEdit: TRxRichEdit; sourceStream:
 TStream);
 
 procedure InsertRTF(aRichEdit:TRxRichEdit; s : String);
 
 procedure CopyRTF(aSource, aDest:TRxRichEdit);
 
 procedure AppendRTF(aRichEdit:TRxRichEdit; s : String);
 
 implementation
 
 uses RichEdit, Messages;
 
 function EditStreamInCallback(dwCookie: Longint; pbBuff: PByte;
 cb: Longint; var pcb: Longint): DWORD; Stdcall;
 var
   theStream: TStream;
   dataAvail: LongInt;
 begin
   theStream := TStream(dwCookie);
   with theStream do
     begin
       dataAvail := Size - Position;
       Result := 0;
       if dataAvail <= cb then
         begin
           pcb := Read(pbBuff^, dataAvail);
           if pcb <> dataAvail then
             result := DWord(E_FAIL);
         end
       else
         begin
           pcb := Read(pbBuff^, cb);
           if pcb <> cb then
             result := DWord(E_FAIL);
         end;
     end;
 end;
 
 function EditStreamOutCallback(dwCookie: Longint; pbBuff: PByte; cb:
 Longint; var pcb: Longint): DWORD; stdcall;
 var theStream: TStream;
 begin
   theStream := TStream(dwCookie);
   with theStream do
     begin
       if cb > 0 then
         pcb := Write(pbBuff^, cb);
       Result := 0;
     end;
 end;
 
 procedure GetRTFSelection( aRichEdit: TRxRichEdit; intoStream:
 TStream );
 var editstream: TEditStream;
 begin
   with editstream do
     begin
       dwCookie:= Longint(intoStream);
       dwError:= 0;
       pfnCallback:= EditStreamOutCallBack;
     end;
   aRichedit.Perform( EM_STREAMOUT, SF_RTF or SFF_SELECTION,
 longint(@editstream));
 end;
 
 procedure PutRTFSelection( aRichEdit: TRxRichEdit; sourceStream:
 TStream);
 var editstream: TEditStream;
 begin
   with editstream do
     begin
       dwCookie:= Longint(sourceStream);
       dwError:= 0;
       pfnCallback:= EditStreamInCallBack;
     end;
   aRichedit.Perform( EM_STREAMIN, SF_RTF or SFF_SELECTION,
   longint(@editstream));
 end;
 
 procedure InsertRTF(aRichEdit:TRxRichEdit; s : String);
 var aMemStream: TMemoryStream;
 begin
   if Length(s) > 0 then
     begin
       aMemStream := TMemoryStream.Create;
       try
         aMemStream.Write(s[1],length(s));
         aMemStream.Position := 0;
         PutRTFSelection( aRichEdit, aMemStream );
       finally
         aMemStream.Free;
       end;
     end;
 end;
 
 procedure CopyRTF(aSource, aDest:TRxRichEdit);
 var aMemStream: TMemoryStream;
 begin
   aMemStream := TMemoryStream.Create;
   try
     GetRTFSelection(aSource, aMemStream );
     aMemStream.Position := 0;
     PutRTFSelection(aDest, aMemStream );
   finally
     aMemStream.Free;
   end;
 end;
 
 procedure AppendRTF(aRichEdit:TRxRichEdit; s : String);
 var start, length, eventmask : integer;
 begin
  eventmask := SendMessage(aRichEdit.Handle,EM_SETEVENTMASK,0,0);
  SendMessage(aRichEdit.Handle,WM_SETREDRAW,0,0);
  start := aRichedit.SelStart;
  length := aRichEdit.SelLength;
  aRichEdit.SelLength := 0;
  aRichEdit.SelStart := System.Length(aRichEdit.Text);
  InsertRTF(aRichEdit,s);
  aRichEdit.SelStart := start;
  aRichEdit.SelLength := length;
  SendMessage(aRichEdit.Handle,WM_SETREDRAW,1,0);
  InvalidateRect(aRichEdit.Handle,nil,true);
  SendMessage(aRichEdit.Handle,EM_SETEVENTMASK,0,eventmask);
 end;
 
 end.


Después la uso de la siguiente manera´:

Código Delphi [-]
        Stream := TMemoryStream.Create;
        Origen.SelectAll;
        GetRTFSelection( Origen, Stream );
        Stream.Position := 0;
        Destino.SelStart:=Destino.GetTextLen;
        PutRTFSelection( Destino, Stream );
        Stream.Free;

Espero que les sea de utilidad.
Saludos

Última edición por roman fecha: 27-11-2004 a las 04:32:30. Razón: Añadir etiqueta [delphi] para formato de código
Responder Con Cita