Using pictures on component - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Using pictures on component

malackamalacka Posts: 31Member
Hi!

I created a component (descending from TPanel) which contains a TImage control on it.
The component should represent different (file)types, showing their icons in the TImage.
Since i don't know how to handle resource files i did the following:
I put an ImageList (with the pictures) on a DataModule into a separate unit.

[uIcons.pas] - the unit

type TDMIcons = class(DataModule)
TDIcons: TImageList;
...


[TDCtrls.pas] - the component's source file

uses Windows, Graphics, ..., uIcons;

type
TTDPreview = class(TPanel)
private
{ Private declarations }
FName: TFileName;
FType: TPFileType;
...

constructor TTDPreview.Create;
begin
inherited Create(AOwner);
... {other settings}
LoadPicture;
end;

procedure TTDPreview.LoadPicture;
var
Bitmap: Graphics.TBitmap;
DMIcons: TDMIcons;
begin
Bitmap:=Graphics.TBitmap.Create;
DMIcons:=TDMIcons.Create(Self);
try
case FType of
pfNone:DMIcons.TDIcons.GetBitmap(0,Bitmap);
pfRasterMap:DMIcons.TDIcons.GetBitmap(1,Bitmap);

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// This is the wrong part! Smg is wrong with calling GetBitmap
// When i try to create an instance (put it on a form in design time),
// Delphi says "Access violation at address 400F7488 in module 'VCL60.BPL'. Read of address FFFFFFFF."
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

...
end;
...
finally
DMIcons.Free;
Bitmap.Free;
end;
end;


I tried the same source in another program (not component) and it works perfectly.
What's the problem with the DMIcons.TDIcons.GetBitmap(...) ???

Here you can download the source of the component if you need more details:
http://imi.nextra.ro/~sziszi/delphi/TD.zip

Please help me!

Sign In or Register to comment.