Hi,
Das geht wahrscheinlich nur mit
EM_STREAMOUT .
Das sieht dann etwa so aus:
Delphi-Quellcode:
uses
RichEdit;
type
TEditStreamCallBack = function(dwCookie: Longint; pbBuff: PByte;
cb: Longint; var pcb: Longint): DWORD;
stdcall;
TEditStream = record
dwCookie: Longint;
dwError: Longint;
pfnCallback: TEditStreamCallBack;
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: TCustomRichEdit; 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 TForm1.Button1Click(Sender: TObject);
var
ms: TMemoryStream;
begin
// 1. Text markieren
RichEdit1.SelStart := 0; // von
RichEdit1.SelLength := 200; // bis Zeichen ändern!
ms := TMemoryStream.Create;
try
// 2. Rtf Formatierung der Markierung auslesen
GetRTFSelection(RichEdit1, ms);
// 3. Speichern
ms.SaveToFile('c:\test.rtf');
finally
ms.Free;
end;
end;