Solved

Rtf into Richedit component

Posted on 2004-10-12
12
797 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now