[fpc-devel] New language feature suggestion (probably not existing in Delphi)

Hans-Peter Diettrich DrDiettrich1 at aol.com
Wed Dec 1 16:44:21 CET 2010


Max Vlasov schrieb:

> An idea here is to introduce a directive (maybe something else, but 
> directive looks more straightforward), let's call it readonly that 
> forces the method to be able only to read the fields and properties of 
> the object it belongs to and forbid any writing. Sure in this case it 
> only can call only the methods also containing such directive.

That's one of the things that "const" can do in C++.


> I thing there might be some logical contradictions I'm not aware at the 
> moment, but I think they can be resolved with general oop inheritance logic.

My experience with "const" methods in C++ often resulted in a bunch of 
cloned methods, with only calls to other non-const methods removed - a 
maintenance nightmare :-(

A workaround could include the same implementation code twice, with 
conditional compilation of all non-const parts. But since the method 
names of the const and non-const versions must be different, every 
method body must reside in its own include file..

DoDi




More information about the fpc-devel mailing list