Forum > General

Simple record methods

(1/1)

primarypower:
Hello

I'm new to Free Pascal, but really experienced with Delphi until 10 seattle with all modern language features like generics, record methods..

We are considering moving from Delphi to Free Pascal and I'm evaluating some of the language support.

A basic stuff for us is record methods that according to Free Pascal release notes, was added to version 2.6.0. I downloaded Lazarus with Free Pascal 3.0.0 and the following code does not work:

  TMyRecord = record
    Red: Integer;
    Blue: Integer;
    procedure MyMethod1;
    function GetColor: string;
  end;

It says Syntax error, END expected but PROCEDURE found...

So, how am I supposed to use record methods in Free Pascal?

Thanks!

primarypower:
Well guess I found it

Have to set the project to Delphi compatible and remove {$mode objfpc} from unit

Blestan:
no! dont go with delphi compat mode.... for records with methosds you hhave $advancedrecords directive

Leledumbo:

--- Quote from: Blestan on February 28, 2016, 02:02:43 am ---no! dont go with delphi compat mode.... for records with methosds you hhave $advancedrecords directive

--- End quote ---
The OP said he's considering moving from Delphi, so Delphi compatibility mode sounds like a more logical choice for fast porting. Well, except if he's starting from scratch.

Thaddy:

--- Quote from: Blestan on February 28, 2016, 02:02:43 am ---no! dont go with delphi compat mode.... for records with methosds you hhave $advancedrecords directive

--- End quote ---

Is the wrong answer when you need to maintain Delphi compatibility in general or are moving from Delphi.
ObjFPC mode is more strict, yes, and has some nice features by itself, but nowadays most fpc users go for Delphi mode. ObjFpc is by some even considered sectarian (it isn't, but that is the case).
Your answer is correct in that it just enables advanced records but at the expense of having Delphi compatibility.

Leledumbo's answer is much more appropriate.

Navigation

[0] Message Index

Go to full version