Forum
× Discussions for CodeTyphon Object Pascal Programming Language

Question Custom component and RTTI ImageIndex property

  • Roman
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
1 week 3 days ago - 1 week 3 days ago #14138 by Roman
Hello!
I just can’t understand what needs to be done with the ImageIndex property in my own component, so that in the property editor instead of the image number a drop-down list with images is displayed.
TMyComp = class(TComponent)
 { ... any methods and fields ...}
published
  property ImageList : TCustomImageList read FImageList write SetImageList;
  property ImageIndex : TImageIndex read FImageIndex write SetImageIndex default -1; // IDE Property Editor show only numbers, not images!
end;


How to make it like this:
Attachments:
Last edit: 1 week 3 days ago by Roman.

Please Log in or Create an account to join the conversation.

  • Roman
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
1 week 1 day ago #14150 by Roman
I helped myself :P

So that in the IDE property editor of custom component it is possible to select ImageIndex by image from associated ImageList, you need to register your own editor of the Image Index property:
type
  TMyImageIndexEditor = class(TImageIndexPropertyEditor )
  protected
    function GetImageList: TCustomImageList; override;
  end;

  function TMyImageIndexEditor.GetImageList: TCustomImageList;
  begin
    Result := (GetComponent(0) as TMyComponent).FImageList
  end;

procedure Register;
begin
  RegisterComponents('My Tool Tab',[TMyComponent]);
  RegisterPropertyEditor(TypeInfo(TImageIndex), TMyComponent, 'ImageIndex', TMyImageIndexEditor);
end;

Important: property names must be correct, i.e. Images and ImageIndex, as written in RegisterPropertyEditor.

Please Log in or Create an account to join the conversation.