Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Catch-22: RTTI, tkDynArray, tkArray

223 views
Skip to first unread message

Adem

unread,
Aug 26, 2003, 7:24:19 PM8/26/03
to
Hi,

In TypeInfo.pas, the RTTI appears to be able to return
tkDynArray and tkArray for TTypeKind.

If I am not mistaken, RTTI only returns Published properties
and methods, so I should be (somehow) able to have published
properties whose types are arrays.

Yet, when I try to add an array property Delphi tells me
"Published property can not be of type ARRAY".

Now, how do I bypass this seemingly catch-22 and have a
published property that RTTI will report as tkDynArray
or tkArray?

Any info, pointers to snippets?

TVMIA,

Cheers,
Adem

Danny Thorpe

unread,
Aug 26, 2003, 8:13:09 PM8/26/03
to

"Adem" <adem...@excite.com> wrote in message
news:3f4bec23$1...@newsgroups.borland.com...

> Hi,
>
> In TypeInfo.pas, the RTTI appears to be able to return
> tkDynArray and tkArray for TTypeKind.
>
> If I am not mistaken, RTTI only returns Published properties
> and methods, so I should be (somehow) able to have published
> properties whose types are arrays.


RTTI is used for more than just published properties. It's also used for
remote method invocation in SOAP interfaces.

-Danny


Adem

unread,
Aug 27, 2003, 7:03:16 PM8/27/03
to
Danny Thorpe wrote:

Thanks, Danny.

One more question, if I may:

Is there any way I could have a object's property to be recognized
by RTTI as tkDynArray and/or tkArray.

The reason I am asking is, I am trying to map objects to TDataset
and I can not figure out how to handle TArrayFields.

Cheers,
Adem


Danny Thorpe

unread,
Aug 28, 2003, 4:20:00 PM8/28/03
to

"Adem" <adem...@excite.com> wrote in message
news:3f4d...@newsgroups.borland.com...

>
> Is there any way I could have a object's property to be recognized
> by RTTI as tkDynArray and/or tkArray.
>
> The reason I am asking is, I am trying to map objects to TDataset
> and I can not figure out how to handle TArrayFields.

The compiler will not accept syntax that publishes a property whose type is
an array type.

I suppose you could hack up your own RTTI data structure and replace the
RTTI pointer in the class info, but I don't recommend it.

-Danny

Thomas Due

unread,
Sep 1, 2003, 2:26:45 AM9/1/03
to
Why not make the property a set?

--
Thomas Due
Software Developer
Scanvaegt Nordic A/S

Adem

unread,
Sep 2, 2003, 4:11:07 AM9/2/03
to
Thomas Due wrote:

> Why not make the property a set?

Can you please elaborate a little more.

Say, you have a TADTField that consists of fileds

Name: String[40];
Age: Integer;
IsCustomer: Boolean;

how do you represent this sort of thing as a set?

Cheers,
Adem

Thomas Due

unread,
Sep 2, 2003, 5:08:24 AM9/2/03
to
Adem wrote:

I dont, I wasn't aware that it was an array of records. I thought it
was a simple type.

Marc Rohloff

unread,
Sep 2, 2003, 8:50:30 AM9/2/03
to
> Say, you have a TADTField that consists of fileds
>
> Name: String[40];
> Age: Integer;
> IsCustomer: Boolean;
>
> how do you represent this sort of thing as a set?

You would normally use subclasses of TCollection and TCollectionItem to
implement this instead of a dynamic array. Delphi already supplies a lot
of support for this, such as persistance and editing.

Marc

Adem

unread,
Sep 3, 2003, 5:26:22 AM9/3/03
to

Marc,

This makes some sense to me, I am not too sure what though.

Do you mean that I should ha ve a TCollection for each TADTField
and then I should have a different derivative of TCollectionItem
for each subfield?

Hmmmm.. Interesting way to look at things --if I got you right.

Cheers,
Adem


Marc Rohloff

unread,
Sep 3, 2003, 8:32:08 AM9/3/03
to
> Do you mean that I should ha ve a TCollection for each TADTField
> and then I should have a different derivative of TCollectionItem
> for each subfield?
You lost me there. Maybe you should explain exactly what you are trying
to achieve.

There are some examples of properties in the IDE which allow a variable
number of sub-objects. Some examples are the fields and parameters of a
dataset, the actions in an ActionList and the columns in a listview.
These are all implemented using subclasses of TCollection and
TCollectionItem. You could look at the source code for this.

Generally you create a subclass of TCollection (or probably
TOwnedCollection), which acts like the array, and a subclass of
TCollectionItem which is the elements the array holds.

Marc

Adem

unread,
Sep 5, 2003, 1:31:56 AM9/5/03
to
> > Do you mean that I should ha ve a TCollection for each TADTField
> > and then I should have a different derivative of TCollectionItem
> > for each subfield?

> You lost me there. Maybe you should explain exactly what you are
> trying to achieve.

:-)

It seems I lost myself. Instead of looking for it from POW of
mapping objects to datasets, I seem to have reversed it in
my mind.

I'll use TCollection instead of attempting to use arrays as
properties and problem will go away.

Thank you for the reality check.

Cheers,
Adem

0 new messages