1. Technology

Store RTF As A Resource - Load Resource RTF Into a TRichEdit

Store Rich Text Formatted Documents Inside Your Application's Executable


Loading a RTF Stored as a Resource

Loading a RTF Stored as a Resource

The Email course Resources in Delphi applications is perfect for Delphi beginner and intermediate developers as well as for those who want a broad overview of the art of storing more than just program code in an application executable.

If your application needs "external pre-made" files like sounds and other raw data, beside distributing separate files for your application's use, you can add the raw data to your application as a resource.

RTF as a Resource

Here's how to store a pre-made RTF document into the EXE file of your Delphi application, then display it in a TRichEdit control when needed.

1. Create a resource (RC) file:

  appInfo RCDATA myAppInfoDocument.RTF
Save the above ASCII document as "myappresources.rc".

2. Compile the RC file into a RES file, using Resource Compiler (BRCC32). This will create "myappresources.res"

3. Include the resource into your executable by adding the following compiler directive to a unit in your project:

  {$R myappresources.RES}
Build the application.

4. Place a TRichEdit on a form. name it "re". Set the PlainText property to FALSE.

5. Finally, the next code block load the RTF stored as a resource into the rich edit control:

  rs: TResourceStream;
  rs := TResourceStream.Create(hInstance, PChar('appInfo'), RT_RCDATA);
    rs.Position := 0;
    //re.PlainText := false;

Delphi tips navigator:
» Delete Facebook Account From a Delphi Application
« Deactivating TShellTreeView

  1. About.com
  2. Technology
  3. Delphi
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi Tips 2010
  7. Store RTF As a Resource - Load Resource RTF Into a TRichEdit In Delphi Programs

©2014 About.com. All rights reserved.