Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-08

Object properties (note: object not class)

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Neil Graham

Is the absence of properties on Objects an omission by design or simply because no-one has gotten to it yet?

Similarly case statements as they appear in records are not supported. I would quite like to have the functionality to do some sort of union on a data structure that also supported (non-virtual) methods and properties.

I completely understand any reluctance to incorporate the record based case system into objects, it was not the best to begin with, but If the same behaviour could be achieved by another means, it would make coding some things a lot easier.

An example of the sort of thing where something like this would be useful would be in the Matrix unit, which uses objects for both vectors and matrices.

for example

        Tvector2_single=object
            data:Tvector2_single_data;
            constructor init_zero;
            constructor init_one;
            constructor init(a,b:single);
            function length:single;
            function squared_length:single;
        end;

If Length were a property with a setlength method then it would make it easy to do
MyVector.Length:=1;

instead of
MyVector:=MyVector/MyVector.length;

Similarly many users of vectors would like to have X and Y available as well as the data in array form.

Jonas Maebe
to Neil Graham
Neil Graham wrote
Is the absence of properties on Objects an omission by design or simply because no-one has gotten to it yet?

They are supported in fpc and in objfpc mode.

Similarly case statements as they appear in records are not supported.

That's indeed not possible by design. You can always declare record fields which themselves consist of a variant record.

Jonas

Neil Graham
to Jonas Maebe
Jonas Maebe wrote 7 lines
On 26 Aug 2009, at 13:21, Neil Graham wrote: > Is the absence of properties on Objects an omission by design or > simply > because no-one has gotten to it yet? They are supported in fpc and in objfpc mode.

They are? Wonderful! [tries]. Sweet it works :-)

It didn't look like it from

http://www.freepascal.org/docs-html/ref/refse24.html#x56-620005.1

Show quoted text 5 lines
> Similarly case statements as they appear in records are not supported. That's indeed not possible by design. You can always declare record fields which themselves consist of a variant record.

That would do the trick it I can do

  property chicken : Integer read field.subfield;

[tries]. Yay! compiles!