Recent

Author Topic: Generic and none exists class member  (Read 3156 times)

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Generic and none exists class member
« on: March 02, 2016, 08:49:01 am »
I used generics to shrink my code, I add class member and it is compiled fine, but when I compiled it in Delphi, Delphi rejected it, cause Name for example here not defined.

Now my question, is that a feature in FPC (cause i like it) or just a pretty bug?

this my example for it

https://github.com/zaher/lazarus_test/blob/master/generics_demo/GenericDemo.pas

you can remove {$ifndef FPC}: class{$endif} same for it.

Thaddy

  • Hero Member
  • *****
  • Posts: 16781
  • Ceterum censeo Trump esse delendam
Re: Generic and none exists class member
« Reply #1 on: March 02, 2016, 08:52:19 am »
We are not a Delphi support forum.
But which version of Delphi rejects it and what does it say about the code?
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: Generic and none exists class member
« Reply #2 on: March 02, 2016, 09:00:34 am »
My question about FPC not Delphi

"Now my question, is that a feature in FPC (cause i like it) or just a pretty bug?"

Thaddy

  • Hero Member
  • *****
  • Posts: 16781
  • Ceterum censeo Trump esse delendam
Re: Generic and none exists class member
« Reply #3 on: March 02, 2016, 09:32:05 am »
Ah, I see. No it is not a feature perse, but it is a feature.
FPC has two different syntaxes for generics. I still need the Delphi version, though. Then I can show you code that works on both. (Given your example)
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8797
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Generic and none exists class member
« Reply #4 on: March 02, 2016, 12:34:03 pm »
I don't know how Delphi handle it, but FPC generics without constraint allows any property/field/method access of the generic type, up to the point where it's finally specialized with concrete type. Only then the semantic is checked whether the respective identifier really exists or not. I guess If you want to share the code between the two compilers, use generic constraint with a type having Name property.

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: Generic and none exists class member
« Reply #5 on: March 02, 2016, 02:47:59 pm »
Thank you all,i liked the way fpc works, it is better than Delphi, and i can remove alot of code with it

If i want to make Delphi compatible i will care to use generic constraint

 

TinyPortal © 2005-2018