Solved

Rtf into Richedit component

Posted on 2004-10-12
12
834 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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