Re:Loading Bitmap from Resource file
Quote
Jukka Palom?ki wrote:
>At 12:59 16/07/96 -0700, you wrote:
>Gary Olliffe wrote:
>> > You kinda had the right idea when you added the bitmap to the project
>> > resource file. You should add it to a resource file (but NOT the project
>> > resource file). Then add a compiler directive to link the resource file
>> > with your project. If you named the file MYRES1.RES, then add {$R
>> > MYRES1.RES}
>What is the exact place?
>> Another Thing!
>> Call
>> bm.handle := LoadBitmap(HInstance, 'SQUARE');
>> instead!
>> HInstance is the global instance handle of the module your code is executing from.
>Ok, I tried like this:
>{$R+ MYRES1.RES}
In the "Interface" section seems to be the best place to put
the directive and it is definitely:
{$R MYRES.RES}
Quote
>procedure TMyClass.DrawSquare(var bitmap: TBitmap);
>var tmp: TBitmap;
>begin
> tmp := tmp.Create;
> tmp.handle := LoadBitmap(HInstance, 'SQUARE');
> bitmap.Canvas.Draw(10, 10, tmp);
>end;
Don't need this (the compiler is not accepting it, it's ignoring it!)
Quote
>{$R- MYRES1.RES}
>And in the main form unit where is one Image-component and one Button-component:
>procedure TSDIAppForm.Button1Click(Sender: TObject);
>var bm: TBitmap;
> mc: TMyClass;
>begin
> bm := TBitmap.Create;
> bm.width := 100;
> bm.height := 100;
> mc := TMyClass.Create;
> mc.DrawSquare(bm);
> Image1.Picture.Graphics := bm;
>end;
>The above should be fine.
>This doesn't work. Compiler thinks this is alright but nothing is drawn to Image1. If I use LoadFromFile
>instead of LoadBitmap this would work.
>I am not sure if this is the right way to use Resource File Directive but this seemed to be the only way. If I
>put only {$R MYRES1.RES} anywhere I got message "Duplicate Resource Directive (MYRES1.RES)".
When I first started doing this kind of stuff I also got this message, try changing the
filename
and make sure it appears only once in your code.
Quote
>Thank you very many
> Jukka Palom?ki
Let me know if this still doesn't work. I'll have a think about it in the mean-time.
It can be done and I have done it for bitmaps and cursors, so stick with it.
Gary
--
____ /"//"/|__ __
Gary Olliffe <ga...@parallax.co.uk> / /|/ // / / / / /|
Snail Mail : Parallax Solutions Ltd., Stone Court, / __/ / // / /> " <|/
Siskin Drive, Coventy, CV3 4FJ /_/|_|/ // / /_/|/ /|
Tel : +44 (0)1203 514549 |_|/./_//_/ /|_|/|_|/
|_||_|/ Solutions Ltd