Board index » delphi » TRect

TRect

Hi!

I need help with TRect.
When I put in the following code, I'm told that there's a wrong method
declaration in class TForm1.:

  TPoint = record
  X: Longint;
  Y: Longint;
end;
TRect = record
  case Integer of
    0: (Left, Top, Right, Bottom: Integer);
    1: (TopLeft, BottomRight: TPoint);
end;

(That's just the code from the Delphi3 help)

What is wrong with this code or where do I have to put it?

Thanks

WARDER
freakaz...@cityweb.de

 

Re:TRect


Quote
On Wed, 4 Nov 1998 17:55:36 +0100, "WARDER" <freakaz...@cityweb.de> wrote:
>I need help with TRect.
>When I put in the following code, I'm told that there's a wrong method
>declaration in class TForm1.:

>  TPoint = record
>  X: Longint;
>  Y: Longint;
>end;
>TRect = record
>  case Integer of
>    0: (Left, Top, Right, Bottom: Integer);
>    1: (TopLeft, BottomRight: TPoint);
>end;

>(That's just the code from the Delphi3 help)

>What is wrong with this code or where do I have to put it?

What you have is the code *Delphi* uses to define the TRect type. You do
not need to (and should not) include this code in your own applications.
Simply use the TRect type. If you wish to use code such as you describe,
call the type something other than TRect.

To use the TRect type, simply declare a variable of type TRect, fill its
fields with values, and use these values.

  var
    Rect1: TRect;
  begin
    with Rect1 do begin
      Left := 20;
      Top := 0;
      Right := 600;
      Bottom := 100;
    end;
    ... { Use the TRect named Rect 1 }
  end;

//////////////////////////////////////////////////////////////////////////
Steve Koterski                      "The knowledge of the world is only to
Technical Publications              be acquired in the world, and not in a
INPRISE Corporation                 closet."
http://www.inprise.com/delphi          -- Earl of Chesterfield (1694-1773)

Re:TRect


In article <tI%%1.460$gB4.3...@news2.cityweb.de>, "WARDER"

Quote
<freakaz...@cityweb.de> writes:
>When I put in the following code, I'm told that there's a wrong method
>declaration in class TForm1.:

>  TPoint = record
>  X: Longint;
>  Y: Longint;
>end;
>TRect = record
>  case Integer of
>    0: (Left, Top, Right, Bottom: Integer);
>    1: (TopLeft, BottomRight: TPoint);
>end;

Steve is correct that you don't need to re-declare the type, but the error
message said there was a wrong METHOD declaration. You're either putting the
above type declarations in the wrong place (it should be in the 'type' clause)
or you've got some other error in your declaration of a procedure or function.

I would have thought that you _could_ redeclare a TRect and TPoint if you
wanted to - totally poointless though <g>.

Alan Lloyd
alangll...@ao.com

Re:TRect


Quote
>What you have is the code *Delphi* uses to define the TRect type. You do
>not need to (and should not) include this code in your own applications.
>Simply use the TRect type. If you wish to use code such as you describe,
>call the type something other than TRect.

>To use the TRect type, simply declare a variable of type TRect, fill its
>fields with values, and use these values.

>  var
>    Rect1: TRect;
>  begin
>    with Rect1 do begin
>      Left := 20;
>      Top := 0;
>      Right := 600;
>      Bottom := 100;
>    end;
>    ... { Use the TRect named Rect 1 }
>  end;

>//////////////////////////////////////////////////////////////////////////
>Steve Koterski                      "The knowledge of the world is only to
>Technical Publications              be acquired in the world, and not in a
>INPRISE Corporation                 closet."
>http://www.inprise.com/delphi          -- Earl of Chesterfield (1694-1773)

Yes Steve is right, these types have already been declared in another
unit and YOU dont therefore need to redeclare, just ensure you have
included that .pas file in your unit.
There is nothing stopping you redeclaring a type within your unit. Its
visibility will override the default declaration (within your unit). But
this can cause type checking errors, on compilation, if you pass one of
these as a parameter to an external function that is expecting a default
record type.

Technically speaking, I think you may have received the error because
you might have placed your declaration within the bounds of another type
i.e. before rather than after the 'end;' of another object or record.
eg
type TMyForm = class(TForm)
  private
    ....
  public
    ....

// here is problem where there was no end; to close
// TMyForm declaration before declaring TRec
type TRec = record
  ......
end;
Kind Regards - Claire
Software Engineer
email : Cla...@HallworthHome.demon.co.uk

Other Threads