Sign in Join

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

Mailing lists / fpc-pascal / 2012-06

record helper types in 2.6

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Bernd

hello, I am referring to this: http://wiki.freepascal.org/Helper_types

I am using 2.6.1 from the fixes branch, last updated no longer than a week ago.

the wiki mentions this syntax:

TTestHelper = record helper for TTest
  procedure SomeMethod;
end;

Now I must be understanding something completely wrong or doing something incredibly stupid but I can't find it, do I have to enable some mode switch for record helpers to work or is there something else that prevents my code from compiling? I am trying to do the following:

unit purple;
{$mode objfpc}{$H+}
{$if FPC_FULLVERSION < 20600}
  {$fatal *** You need Free Pascal Compiler version 2.6.0 or higher *** }
{$endif}

interface
uses
Classes,
ctypes,

  glib2;
type
  TGListHelper = record helper for TGList
    function Append(Item: Pointer): Pointer;
  end;
and it will generate the following error:
libpurple/purple.pas(77,32) Fatal: Syntax error, ":" expected but "FOR" found

I have stripped down the example to the bare minimum, so the line numbers do not match but in the original file (77,32) points to the "for" in the first line of the type declaration. What is wrong?

Bernd

Sven Barth
to Bernd
"Bernd" wrote
hello, I am referring to this: http://wiki.freepascal.org/Helper_types I am using 2.6.1 from the fixes branch, last updated no longer than a

week ago.

Show quoted text 34 lines
the wiki mentions this syntax: TTestHelper = record helper for TTest procedure SomeMethod; end; Now I must be understanding something completely wrong or doing something incredibly stupid but I can't find it, do I have to enable some mode switch for record helpers to work or is there something else that prevents my code from compiling? I am trying to do the following: unit purple; {$mode objfpc}{$H+} {$if FPC_FULLVERSION < 20600} {$fatal *** You need Free Pascal Compiler version 2.6.0 or higher *** } {$endif} interface uses Classes, ctypes, glib2; type TGListHelper = record helper for TGList function Append(Item: Pointer): Pointer; end; and it will generate the following error: libpurple/purple.pas(77,32) Fatal: Syntax error, ":" expected but "FOR"

found

I have stripped down the example to the bare minimum, so the line numbers do not match but in the original file (77,32) points to the "for" in the first line of the type declaration. What is wrong?

Ops... seems that I have forgotten to mention this: in non-Delphi modes you need to enable the "advancedrecords" modeswitch to be able to declare record helpers.

Regards,
Sven

Bernd
to Sven Barth

2012/6/28 Sven Barth :

Ops... seems that I have forgotten to mention this: in non-Delphi modes you need to enable the "advancedrecords" modeswitch to be able to declare record helpers.

Thank you, I have found it after some more searching. It wasn't placed prominently enough for me at the beginning, so I simply did not see it, although I scanned the document diagonally up and down at least three times. I should try to read more slowly.

Bernd