Solved

Rtf into Richedit component

Posted on 2004-10-12
12
806 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 86
IdTelnet1DataAvailable handler freezes the Application 4 68
Convert Jpg /PNG To GIF 5 120
Best Firemonkey component pack 1 87
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

15 Experts available now in Live!

Get 1:1 Help Now