Mega Code Archive

 
Categories / Delphi / VCL
 

Store RTF As a Resource Load Resource RTF Into a TRichEdit In Delphi Programs

Title: Store RTF As a Resource - Load Resource RTF Into a TRichEdit In Delphi Programs 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: var rs: TResourceStream; begin rs := TResourceStream.Create(hInstance, PChar('appInfo'), RT_RCDATA); try rs.Position := 0; //re.PlainText := false; re.Lines.LoadFromStream(rs); finally rs.Free; end; end;