Forum > FPC development

FPC bug? var h: integer; h = nil?

(1/1)

anyeos:
I don't have the time to report it to bugfile or to check if it is already solved (but I guess it is not solved because the naturity of it).

When I define records like this:


--- Code: ---  TRect = record
x: integer;
  y: integer;
  w: integer;
  h: integer;
  End;

--- End code ---

I declare a var:

--- Code: ---Var
  rectangle: TRect;

--- End code ---

And when I try to assign values:


--- Code: ---begin
  rectangle.x := 10;
  rectangle.y := 20;
  rectangle.w := 50;
  rectangle.h := 60; 
end;

--- End code ---

A breakpoint in the beginning of the assignment pause the program in that place. Then I evaluate the values and guess what:


--- Quote ---rectangle.h = Type TRECT has no component named h.
--- End quote ---

Sometimes in some uncommon situation assigning a value to h in any record or class what have a h name gives me a SIGSEGV.
The special case is with SDL2 calling SDL_RenderCopy or SDL_RenderCopyEx where that functions try to assign values to a TSDL_Rect type, specially in the h component.


In a near finished work/program that I am developing when I use intensively types like the TRect declared above, I give a lot of "Type <kind of type> has no component named h" or sometimes a problem with the name y too (I don't remember now if it is the same problem, but appears to be related).
And that don't let me evaluate or modify the "h" named fields.

It appears that h is used internally? Or the compiler for some reason is confusing the h with something other thing.

If I use complete names like "height":


--- Code: ---  TRect = record
  x: integer;
    y: integer;
    width: integer;
    height: integer;
  End;
--- End code ---
     

It works as expected. It shows the values.

But If I declare h alone:

--- Code: ---Var
  h : integer;


--- End code ---

And in the breakpoint code:


--- Code: ---h := 135;
--- End code ---

The evaluate/modify says: h = nil

How that can be possible? H is integer! not pointer! how it can be nil?

If I try to assign a nil value to some integer type I get the error:
'Error: Incompatible types: got "Pointer" expected "Longint"

So, something is wrong in FPC using the name 'h'.

Is h some reserved var? As I know is not.

What is happening then?

howardpc:
You are redefining the TRect type (defined in the types unit) which is used extensively in a GUI environment such as the LCL.
Because use of TRect is so widespread in FCL/LCL source code, you may not need

--- Code: ---uses types;

--- End code ---
anywhere explicitly in your code for the compiler and codetools to know it and assume use of types.TRect rather than your redefined TRect version.
Better to rename your type as TMyRect (or almost anything other than TRect). That will solve your problem immediately.

Martin_fr:
There are several issues that you describe.

On one side there are issues with code not compiling, or crashing.
On the other side there are issues with the debugger.

I can try to help with the latter. (And in fact woul like to know more about them, in order to see, if they can be fixed or not)

However from the samples you gave, I can not reproduce any of them.

You can either get me the full source (and project settings, and then hopefully, I can reproduce the issue).

Or you can generate a log please (Or do both).
Logs:
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

The only known issue with the debugger and record types (and it would apply to cases where several different declarations with the same name apply) is
   array [] of record

(Maybe it also applies to var param / not sure)


---
Also ensure your setup: http://wiki.lazarus.freepascal.org/Debugger_Setup

Navigation

[0] Message Index

Go to full version