Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Brauch RTF Code für Text (https://www.delphipraxis.net/20916-brauch-rtf-code-fuer-text.html)

toms 25. Apr 2004 12:21

Re: Brauch RTF Code für Text
 
Zitat:

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;

Nicolai1234 25. Apr 2004 12:26

Re: Brauch RTF Code für Text
 
[edit] Ich bin ein Trottel :wall: [/edit]

toms 25. Apr 2004 12:30

Re: Brauch RTF Code für Text
 
Ist seltsam, bei mir funktioniert's so.
Lade mal ein Demo-Projekt hoch, dann kann ich's testen.

Nicolai1234 25. Apr 2004 12:41

Re: Brauch RTF Code für Text
 
Ne jetzt klappt alles. Aber nachdem ich den Text hinzugefügt habe (mit putRTFselection) dann macht er danach immer einen Zeilenumbruch! Woran liegt das?


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:44 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz