Recent

Author Topic: Pointers in Tag Property  (Read 6058 times)

JimKueneman

  • Full Member
  • ***
  • Posts: 246
Pointers in Tag Property
« on: March 24, 2013, 05:56:42 pm »
In Delphi I would create a class or structure and store a pointer to it in the Tag property of components.  With the cross platform when I cast pointers to integers I get "not portable" messages. 

What is the correct cross platform way to store a pointer to a class or structure in a LCL component?

Thanks,
Jim

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4599
  • I like bugs.
Re: Pointers in Tag Property
« Reply #1 on: March 24, 2013, 06:24:24 pm »
In Delphi I would create a class or structure and store a pointer to it in the Tag property of components.  With the cross platform when I cast pointers to integers I get "not portable" messages. 

Use PtrInt instead of Integer.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Pointers in Tag Property
« Reply #2 on: March 24, 2013, 11:30:36 pm »
For casting pointers would it not be safer to use PtrUInt?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Pointers in Tag Property
« Reply #3 on: March 24, 2013, 11:34:21 pm »
it doesn't make any difference what so ever other than how the compiler will interpret the data in memory when asked to print them. Casting is the action to ask the compiler to handle a piece of memory in as a certain type it does not convert the data in the memory to the type requested.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Pointers in Tag Property
« Reply #4 on: March 25, 2013, 04:01:34 am »
Quote
For casting pointers would it not be safer to use PtrUInt?
Depending on the operation. Tag property is an Integer (signed), so it's better to use PtrInt. But if the operation is some kind of pointer arithmetic (manipulated as integer) then PtrUInt is correct (otherwise you might get negative address).

PascalDragon

  • Hero Member
  • *****
  • Posts: 6035
  • Compiler Developer
Re: Pointers in Tag Property
« Reply #5 on: March 25, 2013, 05:20:43 pm »
Tag property is an Integer (signed), so it's better to use PtrInt.

The first part of that statement is not entirely correct. "Tag" is declared as a "PtrInt" since November 2010, so the signed part is true, but the Integer part only on 32-bit systems.  :D

Regards,
Sven

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Pointers in Tag Property
« Reply #6 on: March 25, 2013, 06:38:55 pm »
Quote
The first part of that statement is not entirely correct. "Tag" is declared as a "PtrInt" since November 2010
OK, I really really seldom touched that property actually :-[

 

TinyPortal © 2005-2018