Recent

Author Topic: Create in Records?  (Read 6660 times)

sarason

  • Jr. Member
  • **
  • Posts: 77
Create in Records?
« on: July 31, 2014, 01:26:04 pm »
Are there any plans to add the Delphi Create constructor to records and packed records?

regards sarason

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Create in Records?
« Reply #1 on: July 31, 2014, 01:37:02 pm »
AFAIK you have to use {$mode delphi} or some directive for enabling advanced records in objfpc mode.
Note that I personally don't use them but I did a quick test in delphi mode now and it works (compiles).
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

sarason

  • Jr. Member
  • **
  • Posts: 77
Re: Create in Records?
« Reply #2 on: July 31, 2014, 01:44:04 pm »
Excellent!  thankyou!!!

sarason

sarason

  • Jr. Member
  • **
  • Posts: 77
Re: Create in Records?
« Reply #3 on: July 31, 2014, 03:14:22 pm »
I typed to soon.

The code:
unit MemoryBlock;

{$IFDEF FPC}
 //{$mode delphi}
{$MODE OBJFPC}
{$ENDIF}
interface

uses
  Classes;


type

TMemoryBlock = packed record
    Identifier: LongInt;
    Block: Pointer;
    Size: LongInt;
    Lock: Boolean;
    State: Byte;
    Pad1, Pad2: Byte;

    constructor Create(nbytes: Integer); // lazarus issue

  end;       

got

MemoryBlock.pas(25,5) Fatal: Syntax error, "END" expected but "CONSTRUCTOR" found
in objfppc

MemoryBlock.pas(25,5) Error: Constructors aren't allowed in records or record helpers
in delphi

So do you have a magic setting for the compile environment?

sarason

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: Create in Records?
« Reply #4 on: July 31, 2014, 06:05:55 pm »
AFAIK, Constructors on records are not implemented on FPC, until 2.7.1:

http://wiki.freepascal.org/delphi_language_features_which_fpc_does_not_have

I'm still waiting for Destructors on records. :(
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Create in Records?
« Reply #5 on: July 31, 2014, 07:05:06 pm »
However, with FPC 2.6.4 (at least, possibly earlier 2.6.x) you can use {$modeswitch advancedrecords} to add an old-style Init function to your record, even if you are not using 2.7.1

sarason

  • Jr. Member
  • **
  • Posts: 77
Re: Create in Records?
« Reply #6 on: July 31, 2014, 08:46:15 pm »
Thankyou. I will have to Upgrade!!

Howardpc, Edson and Blaazen

regards sarason

 

TinyPortal © 2005-2018