Solved

Loading Custom Resources

Posted on 1998-03-04
7
162 Views
Last Modified: 2010-04-06
I want to load custom resources into a TMemoryStream. I have made a *.RES file with custom data types (using Borland Workshop).  But my app keeps saying "Resource not found error". I am trying to load it with the command

FCompressedStream := TResourceStream.Create(HInstance, ResName, RT_RCDATA);

---------------------
Extra info
---------------------
I'm using D3 and Win95.

The custom resource happens to be a compressed bitmap. (Yes, I really really do want to compress it - it makes my EXE infinitly smaller and then I decompress it once only at run time).
0
Comment
Question by:WarrenYoungEdinburgh
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360075
Hi,

have you added the following in the compiler directive in the implementation
               section of your unit. {$R ResourceFilename} ?

Regards, zif.

0
 

Author Comment

by:WarrenYoungEdinburgh
ID: 1360076
Yes I have added that, with the .res on the end of the filename.
0
 

Author Comment

by:WarrenYoungEdinburgh
ID: 1360077
Judging from the size of the EXE file, it is clear that the resource file is being included in the EXE.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1360078
strange,

What about ...., PCHAR(RT_RCDATA);
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360079
Try also:
  MyResStr := TResourceStream.Create(hInstance, PChar('#123'), PChar('MYSECTION'));
where MYSECTION is the resource group that you have put your resource 123 in.

I wrote the following function, and have used it several times to save a resource to disk:

function ExtractFileFromRes(hLib: Integer; const Filename, ResType, ResName: string): Boolean;
// E.g. ExtractFileFromRes(hInstance, 'C:\Test.exe', 'CUSTOM', '#123');
var
  rs: TResourceStream;
begin
  Result := True;
  try
    rs := TResourceStream.Create(hLib, PChar(ResName), PChar(ResType));
    try
      rs.SaveToFile(Filename);
    finally
      rs.Free;
    end;
  except
    Result := False;
  end;
end;

JB
0
 

Author Comment

by:WarrenYoungEdinburgh
ID: 1360080
Thank you Jim Bob. That solved it. The trick was how to utilise a custom resource type.

Thanks very much.
Warren.
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1360081
Glad it worked.  I assume that I can answer the question then?

JB
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

792 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