Solved

Rtf into Richedit component

Posted on 2004-10-12
12
853 Views
Last Modified: 2013-11-22
Hello there,

I have a large rtf document (file) that I want to put into a RichEdit component - but I want it in there at design time - so I open the rtf document in word - it's laid out nicely. I then copy and then paste into the rtf document (under lines on the object inspector) but it loses all the formating.

So, how can I keep I get that data in there at design time?

Cheers
Nick
0
Comment
Question by:wildzero
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 10

Author Comment

by:wildzero
ID: 12295092
Solved it by opening the file rtf in note pad, copying all the stuff
Then when I add the stuff to the richedit I click code editor and paste it there

sweeet!
0
 
LVL 10

Author Comment

by:wildzero
ID: 12295094
Ahh shoot
it comes out fine then in design view
but when I run the program, it's plain txt.
Pos
0
 
LVL 10

Author Comment

by:wildzero
ID: 12295642
Points increased
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Assisted Solution

by:DragonSlayer
DragonSlayer earned 50 total points
ID: 12295673
you may
1. embed it in a resource file, then load it dynamically during runtime
2. load it from an external file during runtime
0
 
LVL 10

Author Comment

by:wildzero
ID: 12296192
Load it dynamically?
Do tell :) Points have been risen, again for a good reply ;)
0
 
LVL 6

Accepted Solution

by:
david_barker earned 100 total points
ID: 12296369
From http://www.swissdelphicenter.ch/en/showcode.php?id=1049
Autor: Thomas Stutz

(*
  Load RTF file from resource:

  You can store any kind of file as a RCDATA resource.
  The following example shows this with an RTF file.

  Create a text file called textres.rc and put the
  following line in it:

  TESTDOC RCDATA "textdoc.rtf"

  Next, compile that using the Borland Resource Compiler,
  which is provided with Delphi.

  brcc32.exe textres.rc
   
  Your next step is to include the compiled resource (.RES) file into
  your executable, which can be done with the {$R} compiler directive.

*)


implementation

{$R *.dfm}
{$R textres.res}  // <---- your resource file!

procedure TForm1.Button1Click(Sender: TObject);
var
  rs: TResourceStream;
begin
  rs := TResourceStream.Create(hinstance, 'TESTDOC', RT_RCDATA);
  try
    Richedit1.PlainText := False;
    TempStream.Position := 0;
    Richedit1.Lines.LoadFromStream(rs);
  finally
    rs.Free;
  end;
end;


0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 12296817
darn, someone's faster :-p

and to load from external file:

RichEdit1.Lines.LoadFromFile('myrtffile.rtf');
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12300031
Comment

The question was <<So, how can I keep I get that data in there at design time?>>

Not runtime...........

Two possible ways I can think of:

Create a component containing the RTF Component and populate it in code in the initialise event.

Put it in a database table and bind the RTF to the table field - this should dispay the RTF at designtime if the controls are active.


Voodooman

0
 
LVL 6

Expert Comment

by:david_barker
ID: 12300160
Voodoman,

In my solution, the data is in the application at design-time.
It's just it's not in the TRichEdit component but in the resource section of the .EXE
Even if it is not exactly what was initialy asked, I think it's the closest, because I assume the goal is to have the RTF in the application, and not in an outside file (or database).
And of course, my TForm1.Button1Click() could be replaced by the TForm1.OnCreate() event so that the process happens at application startup.

David
0
 
LVL 10

Author Comment

by:wildzero
ID: 12300199
Thats great, I will try it out soon
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12303213
Hi David

No worries...

Another way of course would be to use something like EasyTable from www.aidaim.com.

This is a database product, but you can embed the database in the .exe.

You could then have any number of texts in the RTF - as many as were in the database.

You cannot of course edit the records or add to them.

This would be a very easy way as you would not have to use a resource file editor (or indeed no anything about resources!!!).

Like most people on EE, I comment only on interesting items (my 10 cents) an this was very interesting!!

Regards

Voodooman

0
 
LVL 6

Expert Comment

by:david_barker
ID: 12305363
Hi Voodoman,

I just rushed to read more about EasyTable. Interesting product, thanks for the tip !
Could be very useful in quite a few situations.

Regards,

David
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question