1
votes

I am a C++ programmer primarily, I use Embarcadero C++ Builder and often find I have to write things in Delphi. I have some custom components in a package library, some in C++ and some in Delphi. My specific problem is regarding a component written in Delphi.

This component streams properly to the DFM file, but is not including the collection items. The collection items are visible in the IDE and can be set properly.

I have tried including collection items that are working on another component written in C++. The collection items in question are written in Delphi.

The non working component is written in Delphi, all of the other properties appear to work except this collection. The same collection class does stream properly when included in another component (built in C++).

I understand that streaming comes from the TPersistent class and that Ownership is important to have things stream properly (as well as work in the IDE - which it does).

Both of the TComponent objects declare a published property for the TCollection. In the object written in Delphi it's declared as follows:

  protected:
    {... various other members ...}
    function  _GetOptions: TITIOOptionChoices; virtual;

  published:
    {... various other members ...}
    property  Options: TITIOOptionChoices read _GetOptions;

In the object written in C++ it's declared as follows:

protected:
  virtual TITIOOptionChoices * __fastcall _GetOptions();
  virtual void          __fastcall    _SetOptions(TITIOOptionChoices *pNewValue);

published:
  TITIOOptionChoices  __property  * Options = { read=_GetOptions, write=_SetOptions };

The Delphi Component instantiates the collection in it's create method with this code:

constructor TITIOFNCUIStyleMatrix.Create(AOwner: TComponent);
  begin
    inherited Create(AOwner);
    { other property setup code }
    Self._pOptions := TITIOOptionChoices.Create(Self);
  end;

The working component, written in C++, creates the collection within the AfterConstruction method with the following code:

void __fastcall TITIOFNCOptionChooser::AfterConstruction()
{
  // other property setup code
  this->_pOptions=new TITIOOptionChoices(this);
}

Both components inherit from TComponent. Both controls allow me to set the collection items correctly in the IDE, but only one of them sucessfully streams the collection to the DFM file.

I have not been able to find any reason why one of my components does stream the contents of the property and the other doesn't. However this suggests that the problem is with how the collection is instantiated as it works within one component and not within another.

What have I missed?

1
It might be needed to show more of the TComponent descendants, especially definition of the properties this question is about. Keyword stored for example might be the reason, but hard to tell if defnition is missing.nil
Thanks nil - I had not included the write specifier ... I don't know how I missed that given that I've been looking at this for some time. Your comment enabled me to fix the problem!Rob Lambden

1 Answers

0
votes

Thanks to the input from the community I have answered the question ...

The Collection property did not have a write accessor specified in the Delphi class.

The IDE did show changes, but (I assume) was not able to write these changes back to the object - and so the object would not stream them.

I had implemented both Assign and AssignTo methods for the collection, I just needed to call the Assign method in the write accessor.

Doh!