Recent

Author Topic: new Component with TCollection cannot edit in OI  (Read 3313 times)

webcss

  • Newbie
  • Posts: 6
new Component with TCollection cannot edit in OI
« on: August 27, 2010, 09:18:27 pm »
Hi,

I've created a new nonvisual TComponent descent with a TCollection descent. Collection is a published property of my component.
When I drop the component on a form and try to edit the collection, Error "Collection=nil" shows.
Collection is created in component's constructor.

What am I doing wrong?

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: new Component with TCollection cannot edit in OI
« Reply #1 on: March 26, 2011, 04:11:05 am »
Because I saw the same error and I found this post without reply I give here explanation.

This error simply happens when TCollection is not created.
Example:

If declaration is like this:
Code: [Select]
TItem = class (...)
  ...

TItems = class (TCollection)
  ...

TMyComponent = class (TComponent)
  FItems: TItems;
  ...
  constructor Create;
  ...

then constructor must be like this:

Code: [Select]
constructor TMyComponent.Create;
begin
  inherited Create;
  FItems:=TCollection.Create(TItem);  //error occurs without this line
end;
« Last Edit: March 26, 2011, 12:17:14 pm by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018