[fpc-devel] Property overloading vs. property array enumerators

Kazantsev Alexey kazantsev.alexey at mail.ru
Thu Jan 28 20:02:21 CET 2016


On Thu, 28 Jan 2016 22:33:39 +0400, Ondrej Pokorny <lazarus at kluug.net>  
wrote:

> why the double-posting?

Because my example answer to your querys:

> First, I don't want to publish the TEnumeratedObjects object to the  
> outside of TTest (e.g. you could call Free on it and do other stuff I  
> don't want to be allowed).

You can return record, and what is more, record of nested private type  
(i.e. user can use your type, but can't declare variable of your type).

> Second, TEnumeratedObjects doesn't even need to exist! What about  
> "virtual" array properties that are not mapped to existing objects?

It because your example very simple. In more complex cases we can have  
other methods/overloaded operators in returned record. And it more  
flexible solution.

TValueArray = Array Of TObj.TValue;

var va : TValueArray;

Obj.Values.Sort;

va := Obj.Values;

-- 
Kazantsev Alexey



More information about the fpc-devel mailing list