Recent

Author Topic: Problem with TRec  (Read 1951 times)

dcom67

  • New Member
  • *
  • Posts: 14
Problem with TRec
« on: August 31, 2020, 03:06:14 pm »
I can use TRec with no problems until i add windows to the uses , then it complains of a syntax error ,
try this  code with and without the windows , in the uses.

I kind of need the windows uses in because i want to be able to change the cursor , is there some other way ?

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs,windows;

type

  { TForm1 }
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  private
  public
  end;
var
  Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
var
ImageRect : TRect;
begin
      ImageRect := Rect(24,24,1512,1512);
end;

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Problem with TRec
« Reply #1 on: August 31, 2020, 03:18:19 pm »
If there's some duplicity, you can adress the right type specifically:
Code: Pascal  [Select][+][-]
  1. R: types.TRect;
  2. S: windows.TRect;
The same if there's conflict in function name Rect();.
I'm not on Windows so I can't test.

Note: there's declaration in unit classes.
Code: Pascal  [Select][+][-]
  1. TRect=Types.TRect;
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/

dcom67

  • New Member
  • *
  • Posts: 14
Re: Problem with TRec
« Reply #2 on: August 31, 2020, 03:34:39 pm »
If there's some duplicity, you can adress the right type specifically:
Code: Pascal  [Select][+][-]
  1. R: types.TRect;
  2. S: windows.TRect;
The same if there's conflict in function name Rect();.
I'm not on Windows so I can't test.

Note: there's declaration in unit classes.
Code: Pascal  [Select][+][-]
  1. TRect=Types.TRect;

Ah Ok . Yah i want to keep using the Types.TRec  , as i already have a bunch of them in the code  I will try out  "R: types.TRect;"   thanks

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12719
  • FPC developer.
Re: Problem with TRec
« Reply #3 on: August 31, 2020, 04:07:50 pm »
Are you using an really old version? This difference should be fixed in 3.0.4 (and maybe even 3.0.2)

jamie

  • Hero Member
  • *****
  • Posts: 7607
Re: Problem with TRec
« Reply #4 on: August 31, 2020, 04:17:32 pm »
Put WINDOWS at the start of the USES list not at the end.

This way the compiler sees the WNIDOWS unit last when searching for TRECT. etc...

Search order for units are the last one in the list as the one that gets searched first
The only true wisdom is knowing you know nothing

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Problem with TRec
« Reply #5 on: August 31, 2020, 04:19:17 pm »
I can use TRec with no problems until i add windows to the uses , then it complains of a syntax error ,
try this  code with and without the windows , in the uses.
ALWAYS mention the exact error message.

But when you don't use Windows unit, you can use Rec() as function.
If you DO use Windows unit you'll get an error.
Code: [Select]
unit1.pas(35,23) Fatal: Syntax error, ")" expected but "," found
That's because Windows has a record Rec (which is NOT a function you can just use).

You can fix this by prefixing the Rec() function with Classes. (where it is defined).

Code: Pascal  [Select][+][-]
  1. var
  2.   ImageRect : TRect;
  3. begin
  4.   ImageRect := Classes.Rect(24,24,1512,1512);

dcom67

  • New Member
  • *
  • Posts: 14
Re: Problem with TRec
« Reply #6 on: August 31, 2020, 05:37:19 pm »
Ok Thanks for the Input guys

And I didn't know about that search order part

 

TinyPortal © 2005-2018