Sign in Join

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

Mailing lists / lazarus / 2011-03

Method in record type, is possible?

13 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

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 =================================================

Reply by email

Graeme Geldenhuys
to silvioprog: Hi. This is possible in Lazarus/FPC?: type TFoo = record Value: string; function…

Op 2011-03-16 04:24, silvioprog het geskryf:

Show quoted text 17 lines
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/

Reply by email

Sven Barth
to Graeme Geldenhuys
Graeme Geldenhuys wrote 30 lines
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

Reply by email

Michael Schnell
to Graeme Geldenhuys: Op 2011-03-16 04:24, silvioprog het geskryf: That is the stupidest feature I have seen in…
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

Reply by email

silvioprog
to Graeme Geldenhuys: Op 2011-03-16 04:24, silvioprog het geskryf: That is the stupidest feature I have seen in…

2011/3/16 Graeme Geldenhuys :
[...]

Show quoted text 6 lines
? ?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 =================================================

Reply by email

silvioprog
to Sven Barth: And since beginning of this year FPC also supports the "advanced record" (you need a…

2011/3/16 Sven Barth :

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 =================================================

Reply by email

silvioprog
to Sven Barth: And since beginning of this year FPC also supports the "advanced record" (you need a…

Oops,

2011/3/16 Sven Barth :

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 =================================================

Reply by email

Paul Ishenin
to silvioprog
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

Reply by email

silvioprog
to Paul Ishenin

2011/3/16 Paul Ishenin :

Show quoted text 6 lines
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 =================================================

Reply by email

Sven Barth
to silvioprog
silvioprog wrote 9 lines
2011/3/16 Paul Ishenin: > 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

Reply by email

Paul Ishenin
to Sven Barth
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

Reply by email

Sven Barth
to Paul Ishenin
Paul Ishenin wrote 7 lines
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

Reply by email