Ver Mensaje Individual
  #1  
Antiguo 28-05-2014
pmarin pmarin is offline
Miembro
 
Registrado: jun 2006
Ubicación: Valencia( España )
Posts: 17
Reputación: 0
pmarin Va por buen camino
Añadir el contenido de un TRichEdit a otro en 64 bits.

Hola,

este tema ya se trató en un otro tema (ver http://www.clubdelphi.com/foros/showthread.php?t=82322), y lo solucione
con el fabuloso código de Zarko Gajic Append or Insert RTF from one RichEdit to Another

El siguiente codigo funciona perfectamente en 32 bits. El problema aparece cuando lo compilo con 64 bits.
No existen errores de compilacion, pero la ejecución falla. He intentado adaptarlo por mi cuenta pero no
me aclaro con los punteros, LongInt, DWORD, etc.

Como TRichEdit uso los componentes DevExpress VCL, pero esto no es la causa del problema.

Por favor, ¿me podrían ayudar a convertir este codigo a 64 bits?

Saludos
Pablo

Código Delphi [-]
 
unit Unit1;
interface
uses
Windows, Classes, RichEdit, SysUtils, cxRichEdit;
implementation
procedure AppendToRichEdit(const source: TStream;
destination : TcxRichEdit) ;
// ======================================================== //
 
// Name: AppendToRichEdit(source, destination)
 
//
 
{ The TRichEdit control does not expose a method to append or insert a piece of RTF
text. It does have a Lines property to let you add more text - but you'll have
trouble if you want to append rich text formatted content - it will be added
as a (ASCII) simple text.
If you want to "move" the entire text from one rich editor to another you can
use streams - but the content of the "destination" rich editor will be totally
overwritten by the "source" editor's text.
Here's a function that allows appending or inserting RTF text from one Stream
to another - using rich edit specific callback functions.
Note: Include "RichEdit" into the USES section
}
var
rtfStream : TEditStream;
szError : string;
 
{ EditStreamReader callback function }
function EditStreamReaderCallback(
dwCookie: DWORD;
pbBuff: Pointer;
cb: LongInt;
pcb: PLongInt): DWORD; stdcall;
var
theStream: TStream;
dataAvail: LongInt;
begin
theStream := TStream(dwCookie);
with theStream do
begin
dataAvail := Size - Position;
Result := $0000;
if dataAvail <= cb then
begin
try
pcb^ := read(pbBuff^, dataAvail);
if pcb^ <> dataAvail then
Result := UINT(E_FAIL);
except
Result := $FFFF;
end;
end
else
begin
try
pcb^ := read(pbBuff^, cb);
if pcb^ <> cb then
Result := UINT(E_FAIL);
except
Result := $FFFF;
end;
end;
end;
end; (*EditStreamReader*)
begin
destination.Lines.BeginUpdate;
try
source.Position := 0;
rtfStream.dwCookie := DWORD(source) ;
rtfStream.dwError := $0000;
rtfStream.pfnCallback := @EditStreamReaderCallback;
with TcxRichEdit(destination.InnerControl) do
SendMessage(Handle,
EM_STREAMIN,
SFF_SELECTION or SF_RTF or SFF_PLAINRTF, LPARAM(@rtfStream));
if rtfStream.dwError <> $0000 then
begin
szError := Format('AppendToRichEdit: Error appending RTF data ' +
'with error = %s.', [ IntToStr(rtfStream.dwError) ]);
raise Exception.Create( szError );
end;
finally
destination.Lines.EndUpdate;
end;
(*AppendToRichEdit*)
end;
 
end.
Responder Con Cita