Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading Custom Resources

Posted on 1998-03-04
7
Medium Priority
?
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 400 total points
ID: 1360081
Glad it worked.  I assume that I can answer the question then?

JB
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

705 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