Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Glyphs Froms Resources

Title: Glyphs Froms Resources Question: When you handle to set a really pretty interface to a program n' you wanna skin each component without using external components you can do it by images, but lots of them, so, if your application is big, Delphi takes a lot to open the project or sometimes it just stack while loading with a message like "Line to long" n' all your work goes dumped Answer: To avoid this you can send your application to do it in execution n' work in delphi just as simple components without the images/glyphs, you can load 'em from files but... people like to play with them so better set 'em as resources into you app. Here's how to set a Glyph from a resource procedure TForm1.FormCreate(Sender: TObject); var Corriente : TResourceStream; Imagen : TJPEGImage; Bitmap : TBitmap; begin Imagen:=TJPEGIMAGE.Create; Corriente:=TResourceStream.Create( hInstance,'#3',RT_RCDATA ); Corriente.Seek(0,soFromBeginning); Imagen.LoadFromStream(Corriente); Image1.Canvas.Draw(0,0,Imagen); Imagen.Free; Corriente.Free; begin Bitmap := TBitmap.Create; Corriente := TResourceStream.Create( hInstance,'#4',RT_RCDATA); Corriente.Seek(0,soFromBeginning); Imagen.LoadFromStream(Corriente); SpeedButton1.Glyph := Bitmap; end; Bitmap.Free; Corriente.Free; Imagen.Free; end; I save the resource as a JPG cuz if I save directly as a Bitmap the size encreases a lot, you can set this in fuctions to avoid having n enourmous list in your OnCreate Event goes like this Private procedure LoadG1(sender: TObject); ... Implementation procedure TForm1.LoadGl(Sender: TObject); var Corriente : TResourceStream; Imagen : TJPEGImage; Bitmap : TBitmap; begin Imagen:=TJPEGIMAGE.Create; Corriente:=TResourceStream.Create( hInstance,'#3',RT_RCDATA ); Corriente.Seek(0,soFromBeginning); Imagen.LoadFromStream(Corriente); Image1.Canvas.Draw(0,0,Imagen); Imagen.Free; Corriente.Free; begin Bitmap := TBitmap.Create; Corriente := TResourceStream.Create( hInstance,'#4',RT_RCDATA); Corriente.Seek(0,soFromBeginning); Imagen.LoadFromStream(Corriente); SpeedButton1.Glyph := Bitmap; end; Bitmap.Free; Corriente.Free; Imagen.Free; end; ... procedure TForm1.FormCreate(Sender: TObject); begin LoadGl(Self); end; ----