Question

A component I am working on uses a TCollection to hold links to other components. When the items are edited in the designer their labels look something like this:

0 - TComponentLink
1 - TComponentLink
2 - TComponentLink
3 - TComponentLink

How do I add meaningful labels (the name of the linked component perhaps)? e.g.

0 - UserList
1 - AnotherComponentName
2 - SomethingElse
3 - Whatever

As a bonus, can you tell me how to make the collection editor appear when the component is double clicked?

Was it helpful?

Solution

To display a meaningful name override GetDisplayName:

function TMyCollectionItem.GetDisplayName: string; 
begin 
  Result := 'My collection item name'; 
end;

To display a collection editor when the non visual component is double clicked you need to override the TComponentEditor Edit procedure.

TMyPropertyEditor = class(TComponentEditor)
public
  procedure Edit; override; // <-- Display the editor here
end;

... and register the editor:

RegisterComponentEditor(TMyCollectionComponent, TMyPropertyEditor);

OTHER TIPS

The name displayed in the editor is stored in the item's DisplayName property. Try setting your code to set something like this when you create the link:

item.DisplayName := linkedItem.Name;

Be careful not to change the DisplayName if the user's already set it, though. That's a major UI annoyance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top