Here's my component overall structure:
- My Component
- property Categories: TCollection (of TCategory)
- TCategory
- property Icon: TPicture read FIcon write SetIcon;
- property Example: Integer read FExample write SetExample;
- (Other category properties...)
- TCategory
- (Other properties...)
- property Categories: TCollection (of TCategory)
In the Object Inspector of the IDE, I choose a picture and it gets serialized successfully (I checked it in form view as text). I set a breakpoint on SetIcon
method and when I compile and run the application, it doesn't get called at all. At the same time, SetExample
gets called right as it should.
What's wrong with the TPicture
property?
P.S: Set method is called in IDE, but not at runtime.
Here's a MCVE of the code:
unit MCVE;
interface
uses
System.SysUtils, System.Classes, Vcl.Controls, Graphics, Dialogs;
type
TMyCollectionItem = class(TCollectionItem)
private
FIcon: TPicture;
procedure SetIcon(const Value: TPicture);
public
constructor Create(Collection: TCollection); override;
published
property Icon: TPicture read FIcon write SetIcon;
end;
TMyCollection = class(TCollection)
end;
TMCVE = class(TCustomControl)
private
FCollection: TMyCollection;
procedure SetCollection(const Value: TMyCollection);
public
constructor Create(AOwner: TComponent); override;
published
property MyCollection: TMyCollection read FCollection write SetCollection;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMCVE]);
end;
{ TMyCollectionItem }
constructor TMyCollectionItem.Create(Collection: TCollection);
begin
inherited;
FIcon := TPicture.Create;
end;
procedure TMyCollectionItem.SetIcon(const Value: TPicture);
begin
ShowMessage('SetIcon is called!');
FIcon.Assign(Value);
end;
{ TMCVE }
constructor TMCVE.Create(AOwner: TComponent);
begin
inherited;
FCollection := TMyCollection.Create(TMyCollectionItem);
end;
procedure TMCVE.SetCollection(const Value: TMyCollection);
begin
FCollection := Value;
end;
end.