uses
RichEdit;
// Hilfsroutine für AddRtfFromStream
function _AddRtfCallback(dwCookie: Longint; pbBuff: PByte;
cb: Longint;
var pcb: Longint): Longint;
stdcall;
begin
try
Result := 0;
pcb := TStream(dwCookie).
Read(pbBuff^, cb);
except
Result := 1;
end;
end;
// Ersetzt die aktuelle Auswahl durch den Inhalt des Streams
procedure AddRtfFromStream(RichEditHandle: THandle; Stream: TStream);
var EditStream: TEditStream;
begin
EditStream.dwCookie := LongInt(Stream);
EditStream.dwError := 0;
EditStream.pfnCallback := @_AddRtfCallback;
SendMessage(RichEditHandle, EM_STREAMIN, SF_RTF + SFF_SELECTION, LongInt(@EditStream));
if EditStream.dwError <> 0
then
raise Exception.Create('
RichEdit operation fehlgeschlagen!');
end;
procedure AlteDateiPlusInhaltGleichNeueDatei(
const DieAlteDatei:
string;
RichEdit, TempRichEdit: TJvRichEdit;
const DieNeueDatei:
string);
var MemoryStream: TMemoryStream;
begin
TempRichEdit.LoadFromFile(DieAlteDatei);
TempRichEdit.SelStart := TempRichEdit.Perform(WM_GETTEXTLENGTH, 0, 0);
MemoryStream := TMemoryStream.Create;
try
RichEdit.SaveToStream(MemoryStream);
AddRtfFromStream(TempRichEdit.Handle, MemoryStream);
finally
MemoryStream.Free;
end;
TempRichEdit.SaveToFile(DieNeueDatei);
end;