Recent

Author Topic: [SOLVED] property out of class  (Read 1226 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1800
[SOLVED] property out of class
« on: May 03, 2020, 07:43:03 am »
Is this possible? I remember I saw somewhere that Delphi supports it now (not sure).
I mean defining as following example. Well there are no distinction of private and public, but this might be useful.


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. var
  6.    FA: string;
  7.    function getA : string;
  8.    procedure setA (s: string);
  9.  
  10.    property A : string read getA write setA;
  11. end;
  12.  
« Last Edit: May 04, 2020, 03:11:25 am by egsuh »

Thaddy

  • Hero Member
  • *****
  • Posts: 19276
  • Glad to be alive.
Re: property out of class
« Reply #1 on: May 03, 2020, 09:12:10 am »
I am not aware Delphi supports it, but FPC definitely supports it.
https://www.freepascal.org/docs-html/current/ref/refse27.html As usual, the manual....
« Last Edit: May 03, 2020, 09:16:23 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

jamie

  • Hero Member
  • *****
  • Posts: 7776
Re: property out of class
« Reply #2 on: May 03, 2020, 12:57:20 pm »
Oh cool, I didn't know that existed...
I'll have to test that in Delphi.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 19276
  • Glad to be alive.
Re: property out of class
« Reply #3 on: May 03, 2020, 01:27:33 pm »
If Delphi supports it, it must be the very latest version. 10.1 does not support it.
It may be that Delphi supported it (past) when they were using FPC as their Android/iOS compiler O:-) 8-)
« Last Edit: May 03, 2020, 01:30:29 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

ASerge

  • Hero Member
  • *****
  • Posts: 2503
Re: property out of class
« Reply #4 on: May 03, 2020, 02:36:22 pm »
If Delphi supports it, it must be the very latest version. 10.1 does not support it.
The latest 10.3 also doesn't support this.

jamie

  • Hero Member
  • *****
  • Posts: 7776
Re: property out of class
« Reply #5 on: May 03, 2020, 11:40:07 pm »
I was thinking I could make something that would work as an operator with this of sorts.

 Experimentation is on the way  >:D
The only true wisdom is knowing you know nothing

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12905
  • FPC developer.
Re: property out of class
« Reply #6 on: May 03, 2020, 11:52:18 pm »
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. var
  6.    FA: string;
  7.    function getA : string;
  8.    procedure setA (s: string);
  9.  
  10.    property A : string read getA write setA;
  11. end;
  12.  

Note your indentation suggest something that isn't there. It is actually more


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. var
  6.    FA: string;
  7.  
  8. function getA : string;
  9. procedure setA (s: string);
  10.  
  11. property A : string read getA write setA;
  12. end;
  13.  

The only connection between the parts is the declare before use of get/seta before property A declaration.

egsuh

  • Hero Member
  • *****
  • Posts: 1800
Re: property out of class
« Reply #7 on: May 04, 2020, 03:11:05 am »
WOW,  Great.

I read the sentence that Delphi supports it at a site introducing new features of new Delphi version (edited by another user), not at formal site. I have not confirmed afterwards.

I tried this on my FPC program (few months ago), which was not successful. That's possibly because most of my units are in {$mode Delphi}. The manual says this feature works only in {$mode objfpc}. 


Quote
Note your indentation suggest something that isn't there. It is actually more

You are right. "function" finishes the scope of "var" declaration, so they'd better be indented at the level

 

TinyPortal © 2005-2018