[Lazarus] Method in record type, is possible?

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Method in record type, is possible?

silvioprog
Hi.

This is possible in Lazarus/FPC?:

type
  TFoo = record
    Value: string;
    function AsBoolean: Boolean;
  end;

function TFoo.AsBoolean: Boolean;
begin
  Result := StrToBoolDef(Value, False);
end;

In Delphi:

http://edn.embarcadero.com/article/34324

or:

http://delphi.about.com/od/adptips2006/qt/newdelphirecord.htm

or more:

http://www.google.com/search?sclient=psy&hl=en&site=&source=hp&q=method+for+record+delphi&btnG=Search

Thanks.

--
Silvio Clécio
=================================================
Blog - silvioprog.com.br
Twitter - twitter.com/silvioprog
LazSolutions - code.google.com/p/lazsolutions
Lazarus-BR - http://groups.google.com.br/group/lazarus-br?hl=pt-BR
=================================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

leledumbo
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

Graeme Geldenhuys
In reply to this post by silvioprog
Op 2011-03-16 04:24, silvioprog het geskryf:

>
> This is possible in Lazarus/FPC?:
>
> type
>    TFoo = record
>      Value: string;
>      function AsBoolean: Boolean;
>    end;
>
> function TFoo.AsBoolean: Boolean;
> begin
>    Result := StrToBoolDef(Value, False);
> end;
>
> In Delphi:
>
> http://edn.embarcadero.com/article/34324

That is the stupidest feature I have seen in Delphi. They simply
rehashed something that existed since pre-Delphi v1, and then call it
something "new". What you are looking for is the age old Object structure.

     TFoo = object
       Value: string;
       function AsBoolean: Boolean;
     end;


And yes, FPC supports the Object structure. ;)


Regards,
   - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

Sven Barth
Am 16.03.2011 08:58, schrieb Graeme Geldenhuys:

> Op 2011-03-16 04:24, silvioprog het geskryf:
>>
>> This is possible in Lazarus/FPC?:
>>
>> type
>> TFoo = record
>> Value: string;
>> function AsBoolean: Boolean;
>> end;
>>
>> function TFoo.AsBoolean: Boolean;
>> begin
>> Result := StrToBoolDef(Value, False);
>> end;
>>
>> In Delphi:
>>
>> http://edn.embarcadero.com/article/34324
>
> That is the stupidest feature I have seen in Delphi. They simply
> rehashed something that existed since pre-Delphi v1, and then call it
> something "new". What you are looking for is the age old Object structure.
>
> TFoo = object
> Value: string;
> function AsBoolean: Boolean;
> end;
>
>
> And yes, FPC supports the Object structure. ;)

And since beginning of this year FPC also supports the "advanced record"
(you need a trunk version of course).

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

Michael Schnell
In reply to this post by Graeme Geldenhuys
On 03/16/2011 08:58 AM, Graeme Geldenhuys wrote:
>
> That is the stupidest feature I have seen in Delphi.
Two syntactical descriptions of the same thing are stupid but not that bad.

In fact IMHO, the stupid thing was to rename "record" to "object" in
case that some elements were functions and later "TObject" was defined
as a class and not as an object and thus the "object" Syntax needed to
be depreciated..

So the advanced record structure tries to overcome this.

-Michael

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

silvioprog
In reply to this post by Graeme Geldenhuys
2011/3/16 Graeme Geldenhuys <[hidden email]>:
[...]
>    TFoo = object
>      Value: string;
>      function AsBoolean: Boolean;
>    end;
>
> And yes, FPC supports the Object structure. ;)

But this way would not be possible to use something like this:

TFoo = record...

var
  VFoo: TFoo;
begin
  VFoo[0].Value := 'A';
  VFoo[1].Value := 'B';
...

:/

> Regards,
>  - Graeme -

--
Silvio Clécio
=================================================
Blog - silvioprog.com.br
Twitter - twitter.com/silvioprog
LazSolutions - code.google.com/p/lazsolutions
Lazarus-BR - http://groups.google.com.br/group/lazarus-br?hl=pt-BR
=================================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

silvioprog
In reply to this post by Sven Barth
2011/3/16 Sven Barth <[hidden email]>:
> And since beginning of this year FPC also supports the "advanced record"
> (you need a trunk version of course).

Is there a copy snapshot compatible with that kind of record?

> Regards,
> Sven

--
Silvio Clécio
=================================================
Blog - silvioprog.com.br
Twitter - twitter.com/silvioprog
LazSolutions - code.google.com/p/lazsolutions
Lazarus-BR - http://groups.google.com.br/group/lazarus-br?hl=pt-BR
=================================================
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

silvioprog
In reply to this post by Sven Barth
Oops,

2011/3/16 Sven Barth <[hidden email]>:
> And since beginning of this year FPC also supports the "advanced record"
> (you need a trunk version of course).

Is there a snapshot copy compatible with that type of record?

... Sorry for my translation. ^^'

> Regards,
> Sven

--
Silvio Clécio
=================================================
Blog - silvioprog.com.br
Twitter - twitter.com/silvioprog
LazSolutions - code.google.com/p/lazsolutions
Lazarus-BR - http://groups.google.com.br/group/lazarus-br?hl=pt-BR
=================================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

Paul Ishenin-2
17.03.2011 8:46, silvioprog wrote:

> Is there a snapshot copy compatible with that type of record?

Use FPC 2.5.1 snapshot. You can activate records with methods either by
using {$mode delphi} or by {$modeswitch advancedrecords} in other modes.

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

silvioprog
2011/3/16 Paul Ishenin <[hidden email]>:
> 17.03.2011 8:46, silvioprog wrote:
>
>> Is there a snapshot copy compatible with that type of record?
>
> Use FPC 2.5.1 snapshot. You can activate records with methods either by
> using {$mode delphi} or by {$modeswitch advancedrecords} in other modes.

Yes! Worked perfectely. /o/

My Laz/FPC:

Lazarus 0.9.31 r29435 FPC 2.5.1 i386-win32-win32/win64

Thx to all.

> Best regards,
> Paul Ishenin

--
Silvio Clécio
=================================================
Blog - silvioprog.com.br
Twitter - twitter.com/silvioprog
LazSolutions - code.google.com/p/lazsolutions
Lazarus-BR - http://groups.google.com.br/group/lazarus-br?hl=pt-BR
=================================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

Sven Barth
Am 17.03.2011 03:19, schrieb silvioprog:
> 2011/3/16 Paul Ishenin<[hidden email]>:
>> 17.03.2011 8:46, silvioprog wrote:
>>
>>> Is there a snapshot copy compatible with that type of record?
>>
>> Use FPC 2.5.1 snapshot. You can activate records with methods either by
>> using {$mode delphi} or by {$modeswitch advancedrecords} in other modes.
>
> Yes! Worked perfectely. /o/

The only missing thing are normal constructors currently - class
constructors do work (@Paul: or did you already enable them?)

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

Paul Ishenin-2
17.03.2011 15:23, Sven Barth wrote:

> The only missing thing are normal constructors currently - class
> constructors do work (@Paul: or did you already enable them?)

No. Florian thought to assist me regards record constructors but he has
no time. I don't have a free time to invest into FPC currently :(

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Method in record type, is possible?

Sven Barth
Am 17.03.2011 09:33, schrieb Paul Ishenin:
> 17.03.2011 15:23, Sven Barth wrote:
>
>> The only missing thing are normal constructors currently - class
>> constructors do work (@Paul: or did you already enable them?)
>
> No. Florian thought to assist me regards record constructors but he has
> no time. I don't have a free time to invest into FPC currently :(

Oh. Ok.

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus