Recent

Author Topic: [SOLVED] declaring a record  (Read 1496 times)

JasonLugg

  • Jr. Member
  • **
  • Posts: 67
[SOLVED] declaring a record
« on: February 17, 2018, 05:42:56 pm »
Hi All

Thx in advance.
I am trying to use a record and declare this is the Private section of a form. Yet I keep getting a compile error. Should I declare this elsewhere?

Code: Pascal  [Select][+][-]
  1.     TForm1 = class(TForm)
  2.         CheckBox1: TCheckBox;
  3.         CheckBox2: TCheckBox;
  4.         Edit1: TEdit;
  5.         SpinEdit1: TSpinEdit;
  6.         procedure FormCreate(Sender: TObject);
  7.         procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  8.             Shift: TShiftState; X, Y: Integer);
  9.         procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  10.             Y: Integer);
  11.         procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
  12.             Shift: TShiftState; X, Y: Integer);
  13.         procedure FormPaint(Sender: TObject);
  14.         procedure SpinEdit1Change(Sender: TObject);
  15.     private
  16.         { private declarations }
  17.         MyImage: TBGRABitmap;
  18.         imgX, imgY: integer;
  19.         mX, mY: integer;
  20.         xOffset, yOffset: integer;
  21.         bSelected: Boolean;
  22.         bGrab: Boolean;
  23.         bSnap: boolean;
  24.         iGridSize: Integer;
  25.  
  26.         tImgObj = record
  27.             Plop: integer;
  28.         end;
  29.  
  30.     public
  31.         { public declarations }
  32.  
  33.     end;  
  34.  

Compiler throws:
Fatal: Syntax error, ":" expected but "=" found

What am I doing wrong please?


Needed to put the declaration directly after the
Type
Statement! DOH.
« Last Edit: February 17, 2018, 09:08:10 pm by JasonLugg »

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: declaring a record
« Reply #1 on: February 17, 2018, 06:01:50 pm »
This is the definition of variables, not types, so change "=" to ":".

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: declaring a record
« Reply #2 on: February 17, 2018, 07:08:26 pm »
Try:

Code: Pascal  [Select][+][-]
  1. type
  2.    tImgObj = record
  3.       Plop: integer;
  4.   end;
  5.  
  6.     TForm1 = class(TForm)
  7.     ...
  8.     private
  9.         .....
  10.         bSnap: boolean;
  11.         iGridSize: Integer;
  12.  
  13.         ImgObj: tImgObj;
  14.  
  15.     public
  16.         { public declarations }
  17.  
  18.     end;
  19.  

Bart

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: declaring a record
« Reply #3 on: February 17, 2018, 07:18:41 pm »
Put your tImgObj type into a separate private type section. E.g.

Code: Pascal  [Select][+][-]
  1. type
  2.   TForm = class(TForm)
  3.   private
  4.     ...
  5.   private type
  6.     tImgObj = record
  7.       Plop: integer;
  8.     end;
  9.  
  10.   // if you want to use the type in TForm's declaration you need to start a normal section again
  11.   private
  12.     imgObj: tImgObj;
  13.   end;
« Last Edit: February 18, 2018, 11:21:38 am by PascalDragon »

JasonLugg

  • Jr. Member
  • **
  • Posts: 67
Re: [SOLVED] declaring a record
« Reply #4 on: February 17, 2018, 09:09:09 pm »
Thanks guys!

Very much appreciated [almost as much as the vodka I am currently sipping on!].

 

TinyPortal © 2005-2018