Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#11

Re: Brauch RTF Code für Text

  Alt 25. Apr 2004, 13:21
Zitat von Nicolai1605:
Danke, jetzt habe ich den RTF text. Jetzt hab eich aber probleme ihn in das jvxrichedit reinzumachen! Wie mache ich das?
Hi,

Bei mir funktioniert's so:

Delphi-Quellcode:
uses
  RichEdit;

// RichEdit Type
type
  TMyRichEdit = TJvRichEdit;

// Stream Callback function
type
  TEditStreamCallBack = function(dwCookie: Longint; pbBuff: PByte;
    cb: Longint; var pcb: Longint): DWORD;
  stdcall;

  TEditStream = record
    dwCookie: Longint;
    dwError: Longint;
    pfnCallback: TEditStreamCallBack;
  end;


// EditStreamInCallback callback function
function EditStreamInCallback(dwCookie: Longint; pbBuff: PByte;
  cb: Longint; var pcb: Longint): DWORD; stdcall;
  // by P. Below
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 := UINT(E_FAIL);
    end
    else
    begin
      pcb := read(pbBuff^, cb);
      if pcb <> cb then
        Result := UINT(E_FAIL);
    end;
  end;
end;

procedure PutRTFSelection(RichEdit: TMyRichEdit; SourceStream: TStream);
  // by P. Below
var
  EditStream: TEditStream;
begin
  with EditStream do
  begin
    dwCookie := Longint(SourceStream);
    dwError := 0;
    pfnCallback := EditStreamInCallBack;
  end;
  RichEdit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, Longint(@EditStream));
end;

Beispiel: Rtf Code in TJvRichEdit laden:

Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  SS: TStringStream;
begin
  SS := TStringStream.Create('{\rtf1\ansi\ansicpg1252\deff0\deflang2055{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\fnil MS Sans Serif;}}\viewkind4\uc1\pard\ul\b\f0\fs24 Test\ulnone\b0\f1\fs16\par}');
  try
    PutRTFSelection(JvRichEdit1, SS);
  finally
    SS.Free;
  end;
end;
Thomas
  Mit Zitat antworten Zitat