Recent

Author Topic: TColorBox AddItem  (Read 3880 times)

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 115
TColorBox AddItem
« on: March 20, 2018, 12:50:04 pm »
Hi I'm having the same problem as has been struvk in the Rusian Forum

http://freepascal.ru/forum/viewtopic.php?f=5&t=10379

Quote
RxDBColorBox1.Items.AddObject('SOmeName',TObject(StringToColor('clRed')));

gives an error
Error: Illegal type conversion: "TGraphicsColor" to "TObject"

I'm on 1.8.0 FPC 3.0.4
64bit Windows 8.1 Pro

Is

tobject(ptrint(intptr(Acolor:Tcolor)))

a good solution?

TIA
Paul




taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TColorBox AddItem
« Reply #1 on: March 20, 2018, 03:17:08 pm »
To quote system.pas
Quote
Code: Pascal  [Select][+][-]
  1.   IntPtr  = PtrInt;
  2.  
so that is a double cast in to the same type just use one them.
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

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 115
Re: TColorBox AddItem
« Reply #2 on: March 24, 2018, 04:38:44 am »
Thanks for that,

why do we need to use any of them - is this a bug?

Paul

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TColorBox AddItem
« Reply #3 on: March 24, 2018, 05:19:40 am »
Thanks for that,

why do we need to use any of them - is this a bug?
No its not a bug, it is type safety. The compiler does not know how to cast TColor to a pointer directly so casting it as an integer helps the transition.
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

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 115
Re: TColorBox AddItem
« Reply #4 on: March 24, 2018, 10:21:14 am »
Apparently  Lazarus/32bit does not do this, it only happens with 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14169
  • Probably until I exterminate Putin.
Re: TColorBox AddItem
« Reply #5 on: March 24, 2018, 10:23:58 am »
Apparently  Lazarus/32bit does not do this, it only happens with 64bit.
What?!? Confused. There is no difference.
Specialize a type, not a var.

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 115
Re: TColorBox AddItem
« Reply #6 on: March 24, 2018, 10:36:38 am »
Thanks Thaddy,,

This is what the Russian guys reported as shown in the link earlier in the thread - Google Translated :-) ...

Quote
Good day.

It will be confronted with the fact that in the 64-bit version of lazarus the expression is of the type:


Code: Pascal  [Select][+][-]
  1. RxDBColorBox1.Items.AddObject('Красный',TObject(StringToColor('clRed')));


gives an error

Code: Pascal  [Select][+][-]
  1. Error: Illegal type conversion: "TGraphicsColor" to "TObject"


but at the same time in 32 bit it works without problems.

What is it?

Paul

zeljko

  • Hero Member
  • *****
  • Posts: 1591
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: TColorBox AddItem
« Reply #7 on: March 24, 2018, 02:59:26 pm »
Apparently  Lazarus/32bit does not do this, it only happens with 64bit.

Have you tried TObject(PtrUInt(MyColor)) ?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TColorBox AddItem
« Reply #8 on: March 24, 2018, 03:15:27 pm »
Thanks Thaddy,,

This is what the Russian guys reported as shown in the link earlier in the thread - Google Translated :-) ...

Quote
Good day.

It will be confronted with the fact that in the 64-bit version of lazarus the expression is of the type:


Code: Pascal  [Select][+][-]
  1. RxDBColorBox1.Items.AddObject('Красный',TObject(StringToColor('clRed')));


gives an error

Code: Pascal  [Select][+][-]
  1. Error: Illegal type conversion: "TGraphicsColor" to "TObject"


but at the same time in 32 bit it works without problems.

What is it?

Paul
TColor is a 32bit integer while ptrint/ptruint and pointer changes size from 32 to 64bit.
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

 

TinyPortal © 2005-2018