Hello Martin,
downwards You will find some function to do the Copy task. The function
Copys the *selected* textparts only!
So if You want to copy the whole stuff You have to do something like
this
BufEdit.SelectAll;
CopyRTF(BufEdit,ResultEdit);
where BufEdit and ResultEdit a TRichEdit component.
The Source is not developed by me, but it was placed in a NewsGroup some
month ago.
I dont know if it work with all Richedit librarys - have a test!
Best regards
-=-=-=Source starts
type TEditStreamCallBack = function (dwCookie: Longint; pbBuff: PByte;
cb: Longint; var pcb: Longint): DWORD; stdcall;
TEditStream = record
dwCookie: Longint;
dwError: Longint;
pfnCallback: TEditStreamCallBack;
end;
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; {assume everything is ok}
if dataAvail <= cb then
begin
pcb := Read(pbBuff^, dataAvail);
if pcb <> dataAvail then {couldn't read req. amount of bytes}
result := E_FAIL;
end
else
begin
pcb := Read(pbBuff^, cb);
if pcb <> cb then
result := 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: TRichEdit; 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: TRichEdit; 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:TRichEdit; 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:TRichEdit);
var aMemStream: TMemoryStream;
begin
aMemStream := TMemoryStream.Create;
try
GetRTFSelection(aSource, aMemStream );
aMemStream.Position := 0;
PutRTFSelection(aDest, aMemStream );
finally
aMemStream.Free;
end;
end;
-=-=-=-=Source ends
Quote
"Martin R. Coster" wrote:
> OK, I'm writing a word processing application that uses 2 richedits - one
> visible and the other hidden. At various times I need to copy the complete
> RTF data from the visible to the invisible edit. Now although this is easy
> using a memory stream, the problem is that as soon as I do that it seems to
> empty the Undo list! I'm using the new RichEdit 3.0 dll by the way.
> So, anyone know a) Why does the Undo memory empty? and b) any other way
> anyone knows to get the complete RTF data out of a RichEdit, other than
> SaveToStream?
> On a similar subject, it's reported that the new Richedit 3.0 can turn undo
> memorizing on and off as desired. Anyone know how?
> If worst comes to worst I'll have to write my own undo / redo code, which is
> a bit of a shame...
> Many thanks for any help!
> Martin Coster
--
DomIS Internet Solution - Ekkehard Domning
Spahner Str. 11 - D-49751 S?gel
Tel: +49-5952-9889-5 Fax: +49-5952-9889-6 Mobil: +49-172-8327978
Mail: e...@domis.de Internet: http://www.domis.de