Recent

Author Topic: Casting integers as objects  (Read 2409 times)

WildMan

  • New Member
  • *
  • Posts: 22
Casting integers as objects
« on: September 24, 2019, 04:31:13 am »
I've got a lot of places where I store an integer in the object list for a combobox like this:

SomeComboBox.Items.AddObject('Sample',tObject(Y));

And then retrieve it by casting it the other way...

Y:=LongInt(SomeComboBox.Items.Objects
  • );


That's always worked well but after updating Lazarus and Free Pascal I now get a message Error: Illegal conversion "TObject" to "LongInt" when compiling.  Is it a setting I can't seem to find or is this no longer allowed?

bytebites

  • Hero Member
  • *****
  • Posts: 778
Re: Casting integers as objects
« Reply #1 on: September 24, 2019, 05:06:48 am »
Code: Pascal  [Select][+][-]
  1. Y:=PtrUInt(SomeComboBox.Items.Objects

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Casting integers as objects
« Reply #2 on: September 24, 2019, 05:53:59 am »
That's always worked well but after updating Lazarus and Free Pascal I now get a message Error: Illegal conversion "TObject" to "LongInt" when compiling.  Is it a setting I can't seem to find or is this no longer allowed?
It sounds like you've also updated to 64-bit version.
You can still do TObject to LongInt, but only for 32-bit CPU target.
When you're in 64-bit you might want to use PtrUInt instead.

Thaddy

  • Hero Member
  • *****
  • Posts: 18797
  • Glad to be alive.
Re: Casting integers as objects
« Reply #3 on: September 24, 2019, 07:22:35 am »
And that would be the case for 64 bit Delphi too. It is not Lazarus or FPC specific, not even Pascal specific.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

 

TinyPortal © 2005-2018