Lex Dean wrote:
I'm not making a package
I just want a simple *.DCU
You CANNOT use Proxies.dcu or DesignIDE outside of a design-time
package. PERIOD!!! If your project requires them at run-time then you
are doing something seriously wrong.
I'm considering using TCollection - TCollectionItem
But do not know how to link TCollectionItem to a TGraphicControl
descendant so TCollection editor at design time display the
TGraphicControl descendant in property manager.
There have been NUMEROUS examples posted over the years showing how to
use TCollection in a component. Have you done any searching?
What you are asking for can go one of two different ways, which you
have not elaborated on what you actually want:
1. you want your collection items to refer to external TGraphicControl
controls. Declare a TCollectionItem descendant class that has a
published property of your TGraphicControl-derived class type, then
have your main component create a TOwnedCollection that uses your
TCollectionItem-derived class as its item type.
For example:
type
TMyCollectionItem = class(TCollectionItem)
private
FControl: TMyGraphicControl;
procedure SetControl(AValue: TMyGraphicControl);
published
Control: TMyGraphicControl read FControl write SetControl;
end;
TMyCollection = class(TOwnedCollection)
public
constructor Create(AOwner: TMyComponent); reintroduce;
end;
TMyComponent = class(TComponent)
private
FCollection: TMyCollection;
procedure SetCollection(AValue: TMyCollection);
protected
procedure Notification(AComponent: TComponent; Operation:
TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Collection: TMyCollection read FCollection write
SetCollection;
end;
...
procedure TMyCollectionItem.SetControl(AValue: TMyGraphicControl);
var
Comp: TComponent;
begin
if FControl <> AValue then
begin
Comp := (Collection as TMyCollection).GetOwner as TComponent;
if FControl <> nil then
FControl.RemoveFreeNotification(Comp);
FControl := AValue;
if FControl <> nil then
FControl.FreeNotification(Comp);
end;
end;
constructor TMyCollection.Create(AOwner: TMyComponent);
begin
inherited Create(AOwner, TMyCollectionItem);
end;
constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCollection := TMyCollection.Create(Self);
end;
destructor TMyComponent.Destroy;
begin
FCollection.Free;
inherited;
end;
procedure TMyComponent.Notification(AComponent: TComponent; Operation:
TOperation);
var
I: Integer;
Item: TMyCollectionItem;
begin
inherited;
if Operation = opRemove then
begin
for I := 0 to FCollection.Count-1 do
begin
Item := FCollection[I] as TMyCollectionItem;
if Item.FControl = AComponent then
Item.FControl := nil;
end;
end;
end;
procedure TMyComponent.SetCollection(AValue: TMyCollection);
begin
FCollection.Assign(AValue);
end;
2. you want your collection items to own their own internal
TGraphicControl components, and you want the TGraphicControl's
properties to apear directly in the collection editor when a collection
item is selected. This gets quite a bit more involved, so I'm not
going to write an example here unless this is what you want.
--
Remy Lebeau (TeamB)
Connect with Us