[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 712
  • Last Modified:

question about textRTF property

This question is for anyone that is familiar with both delphi and vb.

I am trying to port a vb app over to delphi and in the source code for the vb app they use the textRTF property of a RichTextBox control and not being a vb guru I went to MSDN and looked it up and it gave me this explanation of what it was.

"Returns or sets the text of a RichTextBox control, including all .rtf code."

which did not really help me alot so I thought I would come here and ask the experts for more info  and more importanly if there is a Delphi equivalent for the textRTF property.

btw if anyone is interested this is the msdn page I looked at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rtfbox98/html/vbprotextrtf.asp

Pete
0
voodoo22
Asked:
voodoo22
  • 9
  • 7
  • 4
2 Solutions
 
shaneholmesCommented:
If you're using the Visual Basic rich text control it has a
.Text property and a .TextRTF property.  The .TextRTF property will return
the text and all the associated format codes, which you can read in with your TRichEdit in delphi.


Shane
0
 
shaneholmesCommented:
Sorry, Then you read in using the TRichEdit.lines.LoadFromFIle

Shane
0
 
Russell LibbySoftware Engineer, Advisory Commented:
You can use the Line.LoadFromFile or the line.LoadFromStream. If you have rtf formatted text, you can save this to a stream (TMemoryStream, TStringStream) then have the RIchEdit control load it by using Lines.LoadFromStream(StreamObject).

Regards,
Russell


eg:

var  Strm:       TMemoryStream;
begin

  RichEdit1.Lines.LoadFromFile('c:\delphi5\demos\richedit\overview.rtf');
  Strm:=TMemoryStream.Create;
  RichEdit1.Lines.SaveToStream(Strm);
  ShowMessage(PChar(Strm.Memory));

  Strm.Position:=0;
  RichEdit1.Lines.LoadFromStream(Strm);

end;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
voodoo22Author Commented:
let me see if i get this right. Using the text property would return the text as it was and using the textRTF would return the RTF Table for the text ???
0
 
shaneholmesCommented:


textRTF would return plain text with format codes

Shane
0
 
shaneholmesCommented:
.text, would return plain text without any formatting

Shane
0
 
voodoo22Author Commented:
ok then obviously my next question is what do you mean by format codes the fsBold , fsUnderline stuff or something else ... could you provide an example of what is returned so I can see what I can expect. I don't need any code just what it would look like.
0
 
shaneholmesCommented:
This is one line

Hello, My Name is Shane! = Plain Text

Here is the same line with formtting (Bold, Italic, & Underline)

See if you can find the words in there.. <smile>

Shane

{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f36\froman\fcharset238\fprq2 Times New Roman CE;}
{\f37\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f39\froman\fcharset161\fprq2 Times New Roman Greek;}{\f40\froman\fcharset162\fprq2 Times New Roman Tur;}{\f41\froman\fcharset177\fprq2 Times New Roman (Hebrew);}
{\f42\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f43\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f44\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;
\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;
\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive \ssemihidden
Default Paragraph Font;}{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv
\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}{\*\rsidtbl \rsid414624\rsid4611214}{\*\generator Microsoft Word 10.0.2627;}{\info
{\title Hello, My Name is Shane}{\author Shane Holmes}{\operator Shane Holmes}{\creatim\yr2004\mo3\dy29\hr20\min22}{\revtim\yr2004\mo3\dy29\hr20\min22}{\version2}{\edmins0}{\nofpages1}{\nofwords3}{\nofchars22}{\*\company .}{\nofcharsws24}{\vern16437}}
\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1800\dgvorigin1440\dghshow1\dgvshow1
\jexpand\viewkind1\viewscale90\viewzk2\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct\asianbrkrule\rsidroot414624 \fet0\sectd
\linex0\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4
\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}
{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0
\fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\insrsid414624\charrsid4611214 Hello}{\insrsid414624 , My }{\i\insrsid414624\charrsid4611214 Name}{\insrsid414624  is }{\ul\insrsid414624\charrsid4611214 Shane}{\insrsid414624 !
\par }}

0
 
Russell LibbySoftware Engineer, Advisory Commented:

Here is an object class that can be used to cast a RichEdit (you could also override the Rich edit itself) and expose both a Text and TextRTF property.

type
  TRichEditCast  =  class(TObject)
  private
     FSelf:      TRichEdit;
     FPlainText: Boolean;
  protected
     procedure   SaveState;
     procedure   RestoreState;
     procedure   SetText(Value: String);
     procedure   SetTextRTF(Value: String);
     function    GetText: String;
     function    GetTextRTF: String;
  public
     constructor Create(RichEditCtl: TRichEdit);
     destructor  Destroy; override;
     property    Text: String read GetText write SetText;
     property    TextRTF: String read GetTextRTF write SetTextRTF;
  end;

implementation

constructor TRichEditCast.Create(RichEditCtl: TRichEdit);
begin

  // Perform inherited
  inherited Create;

  // Set reference
  FSelf:=RichEditCtl;

end;

destructor TRichEditCast.Destroy;
begin

  // Perform inherited
  inherited Destroy;

end;

procedure TRichEditCast.SaveState;
begin

  FPlainText:=FSelf.PlainText;

end;

procedure TRichEditCast.RestoreState;
begin

  FSelf.PlainText:=FPlainText;

end;

procedure TRichEditCast.SetText(Value: String);
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=True;
     stream:=TStringStream.Create(Value);
     try
        FSelf.Lines.LoadFromStream(stream);
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

procedure TRichEditCast.SetTextRTF(Value: String);
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=False;
     stream:=TStringStream.Create(Value);
     try
        FSelf.Lines.LoadFromStream(stream);
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

function TRichEditCast.GetText: String;
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=True;
     stream:=TStringStream.Create('');
     try
        FSelf.Lines.SaveToStream(stream);
        result:=stream.DataString;
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

function TRichEditCast.GetTextRTF: String;
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=False;
     stream:=TStringStream.Create('');
     try
        FSelf.Lines.SaveToStream(stream);
        result:=stream.DataString;
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;


And example usage
--------------------------

begin

  RichEdit1.Lines.LoadFromFile('c:\delphi5\demos\richedit\overview.rtf');

  with TRichEditCast.Create(RichEdit1) do
  begin
     ShowMessage(TextRTF);
     ShowMessage(Text);
     Free;
  end;

end;

If you load the RichEdit1 control with an RTF file, the differences will become apparent. The object class wrapper does
nothing more than encapulate the transfer to/from text for you. Please note, should you decide to
perform the streaming yourself, the PlainText state should be persisted and restored after streaming, because
it does also affect any further loads/saves (both from file as well as stream)

Regards,
Russell
0
 
shaneholmesCommented:
There you go - Russell  Gave you everything you need!

<SMILE>

Shane
0
 
voodoo22Author Commented:
Thanks for the comments but now I am more lost then when I first asked the question and although the comments have not helped me understand this any better I have to award the point so I will just split them up between you guys.
0
 
shaneholmesCommented:
voodoo22,

We would have helped you to understand better. Do you still want help?

Shane
0
 
voodoo22Author Commented:
I do need help thats true but I did not want to waste any more of your guys time with a simple 100 point question but if your willing to then the problem I am having is I don't know how you got all that formatting from the richedit control because when I saved the contents of the control to a text file this is all that showed up.

{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
\viewkind4\uc1\pard\b\f0\fs24 Hello\b0 , My \i Name\i0  is \ul Shane\ulnone !
\par }

and when I reloaded it up into the richedit control it showed up exactly the same as yours did so again I have no idea how you got more then I did.

And as far as rlibbys comment / code goes I have no clue how use it. I am just hobbiest programmer (if you can call me that) and not been doing this for very long and I have never had any training on programmig of any kind and I simply don't know about classes and casting and all that stuff.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

voodoo22....

First, if you didn't understand, you should have asked further questions; not assigned a B grade for this question.

The meaning of TextRTF is the tokenized text that makes up an RTF file. The rich text format (RTF) IS string data, but contains tokens
that must be converted to the appropriate formatting type (such as language, paragraphs, colors, fonts, etc..). As Shane
desribed to you, an example of TextRTF text might look like the following:

<start>
{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f36\froman\fcharset238\fprq2 Times New Roman CE;}
{\f37\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f39\froman\fcharset161\fprq2 Times New Roman Greek;}{\f40\froman\fcharset162\fprq2 Times New Roman Tur;}{\f41\froman\fcharset177\fprq2 Times New Roman (Hebrew);}
<etc...>

This "string" data is run through a converter to apply the correct code page, font, color, paragraph, etc formatting
in the edit window when displayed.

The "Text" property of the RTF file is the raw text that is displayed. Think of it as the output text, minus the paragraph/color/font/etc formatting that is
applied to it when converted from RTF.

----

Russell


0
 
shaneholmesCommented:
OK,

First, From Delphi, Create a New Component by doing the folowing: (From the main menu)

File --> New --> Other

From the "New" tab, double click on "Component" (to create a new component).

A New Component Dialog Box Appears:

Select from the Ancestor Type drop down, TRichEdit (or type it in.

In my Delphi 7, it is listed as "TRichEdit  [ComCtrls]"

Change Class name to :  "TEXtRichEdit1" (no quotes of course)

Click the install button

You wan to install into new package, so select the new package tab
 Browse to your Delphi\Lib folder

Misc

and click the open Button

then OK

then "yes" to Build


Now, in the Unit you have there  unit ExtRichEdit1;

Fill in all the rest of the code as Russell laid out for you above.


You can cust & paste alot of it.

The Compile and you are ready to go, you have a RichEdit for Delphi comparable to your VB one.

Let us know if you get stuck

Shane

Shane






0
 
shaneholmesCommented:
OK, Now when you have the new TRichEdit (TExtRichEdit)  on your Component Pallete, you can use it as Russell laid out:

Shane

And example usage
--------------------------

begin

  ExtRichEdit1.Lines.LoadFromFile('c:\delphi5\demos\richedit\overview.rtf');

  with TExtRichEditCast.Create(RichEdit1) do
  begin
     ShowMessage(TextRTF);
     ShowMessage(Text);
     Free;
  end;

end;
0
 
voodoo22Author Commented:
Ok I did all that and it all seemed to go smoothly until it was time to compile the unit which turned up the following errors.

[Error] EXtRichEdit1.pas(10): ',' or ':' expected but '=' found
[Error] EXtRichEdit1.pas(35): 'END' expected but 'IMPLEMENTATION' found
[Error] EXtRichEdit1.pas(37): Undeclared identifier: 'TRichEditCast'
[Error] EXtRichEdit1.pas(41): This form of method call only allowed in methods of derived types
[Error] EXtRichEdit1.pas(44): Undeclared identifier: 'FSelf'
[Error] EXtRichEdit1.pas(48): Declaration of 'TRichEditCast' differs from previous declaration
[Error] EXtRichEdit1.pas(52): This form of method call only allowed in methods of derived types
[Error] EXtRichEdit1.pas(56): Identifier redeclared: 'TRichEditCast'
[Error] EXtRichEdit1.pas(59): Undeclared identifier: 'FPlainText'
[Error] EXtRichEdit1.pas(59): Undeclared identifier: 'FSelf'
[Error] EXtRichEdit1.pas(63): Identifier redeclared: 'TRichEditCast'
[Error] EXtRichEdit1.pas(66): Undeclared identifier: 'FSelf'
[Error] EXtRichEdit1.pas(66): Undeclared identifier: 'FPlainText'
[Error] EXtRichEdit1.pas(70): Identifier redeclared: 'TRichEditCast'
[Error] EXtRichEdit1.pas(74): Undeclared identifier: 'SaveState'
[Error] EXtRichEdit1.pas(76): Undeclared identifier: 'FSelf'
[Error] EXtRichEdit1.pas(77): Undeclared identifier: 'Value'
[Error] EXtRichEdit1.pas(79): Missing operator or semicolon
[Error] EXtRichEdit1.pas(84): Undeclared identifier: 'RestoreState'
[Error] EXtRichEdit1.pas(89): Identifier redeclared: 'TRichEditCast'
[Error] EXtRichEdit1.pas(93): Undeclared identifier: 'SaveState'
[Error] EXtRichEdit1.pas(95): Undeclared identifier: 'FSelf'
[Error] EXtRichEdit1.pas(96): Undeclared identifier: 'Value'
[Error] EXtRichEdit1.pas(98): Missing operator or semicolon
[Error] EXtRichEdit1.pas(103): Undeclared identifier: 'RestoreState'
[Error] EXtRichEdit1.pas(108): Function needs result type
[Error] EXtRichEdit1.pas(112): Undeclared identifier: 'SaveState'
[Error] EXtRichEdit1.pas(114): Undeclared identifier: 'FSelf'
[Error] EXtRichEdit1.pas(117): Missing operator or semicolon
[Error] EXtRichEdit1.pas(123): Undeclared identifier: 'RestoreState'
[Error] EXtRichEdit1.pas(128): Function needs result type
[Error] EXtRichEdit1.pas(132): Undeclared identifier: 'SaveState'
[Error] EXtRichEdit1.pas(134): Undeclared identifier: 'FSelf'
[Error] EXtRichEdit1.pas(137): Missing operator or semicolon
[Error] EXtRichEdit1.pas(143): Undeclared identifier: 'RestoreState'
[Hint] EXtRichEdit1.pas(13): Private symbol 'FSelf' declared but never used
[Hint] EXtRichEdit1.pas(14): Private symbol 'FPlainText' declared but never used
[Error] EXtRichEdit1.pas(17): Unsatisfied forward or external declaration: '.2.SaveState'
[Error] EXtRichEdit1.pas(18): Unsatisfied forward or external declaration: '.2.RestoreState'
[Error] EXtRichEdit1.pas(19): Unsatisfied forward or external declaration: '.2.SetText'
[Error] EXtRichEdit1.pas(20): Unsatisfied forward or external declaration: '.2.SetTextRTF'
[Error] EXtRichEdit1.pas(21): Unsatisfied forward or external declaration: '.2.GetText'
[Error] EXtRichEdit1.pas(22): Unsatisfied forward or external declaration: '.2.GetTextRTF'
[Error] EXtRichEdit1.pas(25): Unsatisfied forward or external declaration: '.2.Create'
[Error] EXtRichEdit1.pas(26): Unsatisfied forward or external declaration: '.2.Destroy'
[Error] EXtRichEdit1.pas(33): Unsatisfied forward or external declaration: 'TEXtRichEdit1.Register'
[Fatal Error] Misc.dpk(33): Could not compile used unit 'EXtRichEdit1.pas'


and here is the contents of the unit.....................


unit EXtRichEdit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, StdCtrls, ComCtrls;

type
  TEXtRichEdit1 = class(TRichEdit)
  TRichEditCast  =  class(TObject)
  private
    { Private declarations }
    FSelf:      TRichEdit;
    FPlainText: Boolean;
  protected
    { Protected declarations }
     procedure   SaveState;
     procedure   RestoreState;
     procedure   SetText(Value: String);
     procedure   SetTextRTF(Value: String);
     function    GetText: String;
     function    GetTextRTF: String;
  public
    { Public declarations }
     constructor Create(RichEditCtl: TRichEdit);
     destructor  Destroy; override;
     property    Text: String read GetText write SetText;
     property    TextRTF: String read GetTextRTF write SetTextRTF;
  published
    { Published declarations }
  end;

procedure Register;

implementation

constructor TRichEditCast.Create(RichEditCtl: TRichEdit);
begin

  // Perform inherited
  inherited Create;

  // Set reference
  FSelf:=RichEditCtl;

end;

destructor TRichEditCast.Destroy;
begin

  // Perform inherited
  inherited Destroy;

end;

procedure TRichEditCast.SaveState;
begin

  FPlainText:=FSelf.PlainText;

end;

procedure TRichEditCast.RestoreState;
begin

  FSelf.PlainText:=FPlainText;

end;

procedure TRichEditCast.SetText(Value: String);
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=True;
     stream:=TStringStream.Create(Value);
     try
        FSelf.Lines.LoadFromStream(stream);
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

procedure TRichEditCast.SetTextRTF(Value: String);
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=False;
     stream:=TStringStream.Create(Value);
     try
        FSelf.Lines.LoadFromStream(stream);
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

function TRichEditCast.GetText: String;
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=True;
     stream:=TStringStream.Create('');
     try
        FSelf.Lines.SaveToStream(stream);
        result:=stream.DataString;
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

function TRichEditCast.GetTextRTF: String;
var  stream:     TStringStream;
begin

  SaveState;
  try
     FSelf.PlainText:=False;
     stream:=TStringStream.Create('');
     try
        FSelf.Lines.SaveToStream(stream);
        result:=stream.DataString;
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;


procedure Register;
begin
  RegisterComponents('samples', [TEXtRichEdit1]);
end;

end.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

First, the "wrapper" i gave you was so you didn't have to create a new component (as you see above, it inherits from TObject),
It is not an OO extension to the original, although it could be used that way. If you wish to use it as an OO component extension, then
the correct declarations would be as follows:

unit ExtRichEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TExtRichEdit      = class(TRichEdit)
  private
     // Private declarations
     FPlainText:    Boolean;
  protected
     // Protected declarations
     procedure   SaveState;
     procedure   RestoreState;
     procedure   SetText(Value: String);
     procedure   SetTextRTF(Value: String);
     function    GetText: String;
     function    GetTextRTF: String;
  public
     // Public declarations
  published
     // Published declarations
     property    Text: String read GetText write SetText;
     property    TextRTF: String read GetTextRTF write SetTextRTF;
  end;

procedure Register;

implementation

procedure TExtRichEdit.SaveState;
begin

  FPlainText:=PlainText;

end;

procedure TExtRichEdit.RestoreState;
begin

  PlainText:=FPlainText;

end;

procedure TExtRichEdit.SetText(Value: String);
var  stream:     TStringStream;
begin

  SaveState;
  try
     PlainText:=True;
     stream:=TStringStream.Create(Value);
     try
        Lines.LoadFromStream(stream);
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

procedure TExtRichEdit.SetTextRTF(Value: String);
var  stream:     TStringStream;
begin

  SaveState;
  try
     PlainText:=False;
     stream:=TStringStream.Create(Value);
     try
        Lines.LoadFromStream(stream);
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

function TExtRichEdit.GetText: String;
var  stream:     TStringStream;
begin

  SaveState;
  try
     PlainText:=True;
     stream:=TStringStream.Create('');
     try
        Lines.SaveToStream(stream);
        result:=stream.DataString;
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

function TExtRichEdit.GetTextRTF: String;
var  stream:     TStringStream;
begin

  SaveState;
  try
     PlainText:=False;
     stream:=TStringStream.Create('');
     try
        Lines.SaveToStream(stream);
        result:=stream.DataString;
     finally
        stream.Free;
     end;
  finally
     RestoreState;
  end;

end;

procedure Register;
begin
  RegisterComponents('Win32', [TExtRichEdit]);
end;

end.

-----------

Menu | component/install component/dialog button Browse (for Unit file name)/ Select ExtRichEdit.pas (from where ever you saved it)
Compile the packge;  if the dialog does not indicate that TExtRichEdit was installed, then click the "Install" button for the package dialog.
Once installed, you will find the TExtRichEdit component on the Win32 tab of the ide. This can be dropped on the form (instead of TRichEdit).
The component will have all of the TRichEdit properites, as well as the Text and TextRTF properties exposed by the descendant class.


Russell




0
 
voodoo22Author Commented:
Ok I installed the component and ran this code on a button

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExtRichEdit1.Lines.LoadFromFile('goof.txt');
  ShowMessage(ExtRichEdit1.TextRTF);
  ShowMessage(ExtRichEdit1.Text);
end;

goof.txt contained all those RTF codes that shane posted above but when I clicked on the button all that showed in the message box was

{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
\viewkind4\uc1\pard\b\f0\fs24 Hello\b0 , My \i Name\i0  is \ul Shane\ulnone !
\par }

which is obviously not the same thing as what he has above but oddly enough it is the exact same thing I posted above
so which one is correct and don't worry I am going to open a new blank question and award you another 100 points once
I get this thing figured out.
0
 
voodoo22Author Commented:
Nvm I got the program working thx for your help again.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 9
  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now