Mega Code Archive

 
Categories / Delphi / Examples
 

Graphres

Subject: Re: Delphi : component load bitmaps from .DCR or .RES????? It certainly is possible. Use Image Editor (or another Windows resource editor) to create a .RES file. Put your bitmaps in the Bitmaps section. Just DO NOT put them in the .RES file with the same name as your project (.DPR) file. Delphi maintains this resource file and will anything you put in it. In the unit where you wish to access the bitmaps, place a {$R xxxx.RES} in the implementation section, substituting your resource filename for the 'xxxx'. You can then load the bitmaps with something like the following: FBitmap := TBitmap.Create; try FBitmap.Handle := LoadBitmap(hInstance, 'BITMAP_1'); except FBitmap.Free; end; Substitute the name you gave your bitmap in the Bitmap section of the resource file for BITMAP_1, above. (The hInstance variable is a global handle to the application instance, which is defined by Delphi.) Remember, despite what the Delphi documentation may or may not say, the name you give LoadBitmap() IS case sensitive. Typically, you would place this kind of LoadBitmap call in the Create or OnCreate method of your Component/Form/etc. You would then use Canvas.Draw(x, y, FBitmask) to display the bitmap on a canvas. Don't forget to call FBitmap.Free in the Destroy/Close/etc. method to free up the memory allocated for the bitmap. Hope this helps! --Mark R. Johnson ______________________________________________________________________________ Mark R. Johnson _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ Atlanta, GA USA _/ http://www.mindspring.com/~cityzoo/cityzoo.html _/ keeper@mindspring.com _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ ------------------------------------------------------------------------------- From: bstowers@cybernetics.net (Brad Stowers) Subject: Re: DELPHI: TImage with resources Date: Sun, 28 May 1995 16:55:30 GMT {...code begins...} var Bmp: TBitmap; {$IFDEF RESOURCE_IN_DLL} Handle: THandle; {$ENDIF} begin {$IFDEF RESOURCE_IN_DLL} Handle := LoadLibrary('BITMAPS.DLL'); {$ELSE} Handle := hInstance; {$ENDIF} Bmp := TBitmap.Create; {$IFDEF NAME_IS_A_NUMBER} { Typecase the number into a PChar. } Bmp.Handle := LoadBitmap(Handle, PChar(100)); {$ELSE} { Must use uppercase for name } Bmp.Handle := LoadBitmap(Handle, 'MYBITMAP'); {$ENDIF} { Do whatever needs to be done like Canvas.Draw(x,y,Bmp); } Bmp.Free; end; {...code ends...} Regards, Brad -------------------------------------------------------- Brad Stowers | bstowers@cybernetics.net deltaComm Development | My views are my own... Telix for Windows & DOS | Keep yer hands off of 'em. -------------------------------------------------------- http://www.cybernetics.net/users/bstowers/