Sign in Join

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

Mailing lists / fpc-devel / 2015-08

Records nesting/inheritance?

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Sven Barth
to Чернов Дмитрий
"Чернов Дмитрий" wrote
So, there's examples of addressing some fields with and without this

feature:

Show quoted text 8 lines
Friend.BaseUser.FirstName >> Friend.FirstName Friend.UserInfo.Country.ID >> Friend.Country.ID And let me clarify some details: - fields can not be overridden; - record can nest several records. Of course, somebody will try to advise me to use objects. :)

Of course, but probably not the objects you think about ("class"), but their older cousins ("object"). ;)

But never mind that a) in procedural programming we don't use objects,

"object" types behave like records with inheritance if they don't have methods.

b) objects are more complex that needed

Not true for "object" types.

c) objects require additional routines for creating and destroying of

them.

Like records "object" types can be allocated on the stack.

So there is no need to burden "record" with another feature that's already supported by "object".

Note: Multiple inheritance is however supported by none of the three structured types ("record", "object", "class") and it wouldn't be added anyway, so there you need to find a solution with normal inheritance.

Regards,
Sven

Reply by email

Michael Van Canneyt
to Чернов Дмитрий:
Чернов Дмитрий wrote 12 lines
Good day everyone.   Recently I've tried to write some social network parsing code and faced with numerous nesting of structures (records). When I completely tired to write things like Friend.BaseUser.City.ID ("real programmer will never get complerely tired", hah - yes, I know), I thought out that it might be cool to have such a feature as structures inheritance. I'm not very good in English, so, instead of describing everything I'll just try to write an example:   http://pastebin.com/Pm701Nh4   So, there's examples of addressing some fields with and without this feature: Friend.BaseUser.FirstName  >> Friend.FirstName Friend.UserInfo.Country.ID >> Friend.Country.ID

You can do this already with extended records, just declare properties.

http://www.freepascal.org/docs-html/ref/refse51.html#x107-1170009.1

Michael.

Reply by email

Чернов Дмитрий
to Michael Van Canneyt

05.08.2015, 16:20, "Michael Van Canneyt" :

Show quoted text 25 lines
On Wed, 5 Aug 2015, Чернов Дмитрий wrote: >  Good day everyone. > >  Recently I've tried to write some social network parsing code and faced with numerous nesting of structures (records). >  When I completely tired to write things like Friend.BaseUser.City.ID ("real programmer will never get complerely tired", hah - yes, I know), I thought out that it might be cool to have such a >  feature as structures inheritance. >  I'm not very good in English, so, instead of describing everything I'll just try to write an example: > >  http://pastebin.com/Pm701Nh4 > >  So, there's examples of addressing some fields with and without this feature: >  Friend.BaseUser.FirstName  >> Friend.FirstName >  Friend.UserInfo.Country.ID >> Friend.Country.ID You can do this already with extended records, just declare properties. http://www.freepascal.org/docs-html/ref/refse51.html#x107-1170009.1 Michael. , _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email