Question

In Delphi 2010 is there a way to iterate through any kind of indexed property (like Pages of TPageControl, for example)?

Était-ce utile?

La solution

No, this is not possible, as there is not standard pattern that:

  • specifies the index type
  • specifies the start and end values of the index to use

That's why certain classes have enumerators: it is the pattern that tells the for ... in statement how to enumerate it.

What you can do however is a best estimate:

  • most times the index is integer
  • most times the index starts at zero
  • most times there is a property Count or Length that tells you how to obtain the end value

Finally, it is possible to "retrofit" TPageControl with a GetEnumertor using class helpers (or record helpers if the underlying type is a record).

Autres conseils

If I understand you correctly, you want to iterate through these properties via RTTI without knowing anything about the property and its index-values. Because valid index-values must not be a sequence of integer-values this can't be possible. There might be properties with string-indexes or with object-references as index-value. And there is no mechanism in RTTI to query valid index-values wich could be used for an iteration.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top