Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to retrieve rich text from a resource file and save it to disk Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
112
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to retrieve rich text from a resource file and save it to disk

Answer:

These are the basic steps:

Create a resource file
Include it in your project
Load the file from the resource file into a TResourceStream
Create a TFileStream with the filename you want to write to
Use CopyFrom to get the data from the TResourceStream to the TFileStream
Free both the streams

The file is magically written to disk, without any need to call a write procedure 
or anything like that. It takes a file called 'test.rtf' from the resource file 
TEST.RES and saves it out to disk as 'test2.rtf' in the application folder:
1   
2   {$R TEST.RES}
3   
4   procedure TfrmMain.Button1Click(Sender: TObject);
5   var
6     ResStream: TResourceStream
7     MyFileStream: TFileStream;
8   begin
9     try
10      MyFileStream := TFileStream.Create(ExtractFilePath(Application.ExeName) +
11        ' test2.rtf ', fmCreate or fmShareExclusive);
12      ResStream := TResourceStream.CreateFromID(HInstance, 1, RT_RCDATA);
13      MyFileStream.CopyFrom(ResStream, 0);
14    finally
15      MyFileStream.Free;
16      ResStream.Free;
17    end;
18  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC