### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Initializing TRect  (Read 554 times)

#### del

• Full Member
• Posts: 200
##### Initializing TRect
« on: February 24, 2021, 03:06:35 pm »
According to:

https://www.freepascal.org/docs-html/current/rtl/objects/trect.copy.html

I can use

Code: Pascal  [Select][+][-]

to initialize the TRect. But I get this error:

Quote
MyClasses.pas(438,9) Error: identifier idents no member "Assign"

However, when I use this form of initialization, everything is fine:

Code: Pascal  [Select][+][-]
1.  m_mask := Rect(-1, -1, -1, -1);

So obviously I found a solution. The variable m_mask is declared here:

Code: Pascal  [Select][+][-]

FWIW.
« Last Edit: February 24, 2021, 03:08:16 pm by del »

#### howardpc

• Hero Member
• Posts: 3693
##### Re: Initializing TRect
« Reply #1 on: February 24, 2021, 04:10:37 pm »
To use TRect methods such as Assign you need the TRect declared in the Objects unit (as the documentation example shows).
« Last Edit: February 24, 2021, 04:13:52 pm by howardpc »

#### jcmontherock

• Jr. Member
• Posts: 64
##### Re: Initializing TRect
« Reply #2 on: February 24, 2021, 04:11:57 pm »
For that I am using:  Rect := Bounds(Left, Top, Width, Height);  and   Rect.SetBounds(Left, Top, Width, Height);

#### GetMem

• Hero Member
• Posts: 4016
##### Re: Initializing TRect
« Reply #3 on: February 24, 2021, 05:35:40 pm »
@del
You can achieve the same result without the object unit, just use the cross platform CopyRect and EqualRect apis.
Code: Pascal  [Select][+][-]
1. uses LCLIntf;
2.
3. procedure TForm1.Button1Click(Sender: TObject);
4. var
5.   R1, R2, R3: TRect;
6. begin
7.   R1 := TRect.Create(10, 100, 50, 200);
8.   R2 := TRect.Create(10, 100, 50, 200);
9.   R3 := TRect.Create(-1, -1, -1, -1);
10.   CopyRect(R3, R2);
11.   if EqualRect(R1, R3) then
12.     ShowMessage('Equal')
13.   else
14.     ShowMessage('Not equal');
15. end;

#### del

• Full Member
• Posts: 200
##### Re: Initializing TRect
« Reply #4 on: February 24, 2021, 09:31:53 pm »
Thanks everybody.