sobakava Posted October 29, 2015 Posted October 29, 2015 I'm trying to develop a custom unigui component within a TFrame parent. Everything was fine so far but I have to add an icon to this component. I added a Tbitmap property for this. I'm creating and freeing the bitmap in the contructor and destructor. I can change the bitmap at design time using object inspector. My problem is, when I try to remove the component from my form, Delphi crashes with Access Violation error. If I comment out Icon.Free on destructor, it does not crash. unit unit_device_type_a; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIFrame, uniGUIBaseClasses, uniPanel, uniLabel, Vcl.Imaging.pngimage, uniImage, uniEdit; const Fversion = '1.0.0'; type Tframe_device_type_A = class(TUniFrame) panel_parent: TUniPanel; UniPanel2: TUniPanel; label_header: TUniLabel; bitmap_icon: TUniImage; UniLabel1: TUniLabel; UniLabel4: TUniLabel; UniLabel5: TUniLabel; UniImage1: TUniImage; UniImage2: TUniImage; function GetVersion: string; procedure SetVersion(const Value: string); function GetIcon: Tbitmap; procedure SetIcon( icon : TBitmap ); private { Private declarations } public { Public declarations } constructor Create(Aowner: TComponent); override; destructor Destroy; override; published property Version: string read GetVersion write SetVersion; property Icon: Tbitmap read GetIcon write SetIcon; end; implementation {$R *.dfm} constructor Tframe_device_type_A.Create(AOwner: TComponent); begin inherited; Icon := TBitmap.Create; end; destructor Tframe_device_type_A.Destroy; begin Icon.Free; inherited; end; function Tframe_device_type_A.GetIcon: TBitmap; begin result := bitmap_icon.Picture.Bitmap; end; procedure Tframe_device_type_A.SetIcon(icon : TBitmap); begin bitmap_icon.Picture.Bitmap.Assign( icon ); end; end. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.