Recent

Author Topic: Please help me - erro Illegal conversion type "LongInt" to "Integer"  (Read 5253 times)

greaseflog

  • Newbie
  • Posts: 4
Hello,

I need some help to fix this problem.

I'm using Lazarus . Lazarus 1.6 r51630 FPC 3.0.0 x86_64-win64-win32/win64 .

I need to fix this error but i can rewritte code because others peoplo work with me and them doesn't have the iusse.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #1 on: December 09, 2017, 12:32:29 am »
No code to look at = not able to provide help

CuriousKit

  • Jr. Member
  • **
  • Posts: 78
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #2 on: December 09, 2017, 12:39:47 am »
Just giving us the error without any context won't yield any solutions at all.  At the very least you should provide the procedure, or the segment of it, that causes the error, and highlighting which statement causes it.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #3 on: December 09, 2017, 02:57:29 am »
Most likely didn't select a mode to work with, thus defaulting to TP or fpc
using 16 bit integers and 32 bit longint's

Need to ensure a {$mode objpas} or {$mode Delphi) is selected I guess ?
The only true wisdom is knowing you know nothing

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #4 on: December 09, 2017, 03:06:16 am »
You're close jamie :-)

Pay attention to the host. Assuming a mix between 32 and 64 bit. Therby the error makes no sense to me. Probably more in the line of "Error: Illegal type conversion: "LongInt" to "TObject" but, it is still guessing.

When the EError happen in Windows64 Ultimate that i have to do?


erro Illegal conversion type "LongInt" to "Integer"

code result.AddObject(wDescri, TObject (wCodigo))   ;

Lazarus 1.6
SVN r51630
FPC 3.0.0
x86_64-win64-win32/win64
Missing information:
Declaration/types for result, wDescri and wCodigo, and you'd better not have redeclared TObject else add that declaration/type as well.

I'd have more luck winning the lottery instead of playing guessing games and scamming other threads for finding a response  ;D
« Last Edit: December 09, 2017, 03:14:53 am by molly »

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #5 on: December 10, 2017, 12:42:24 am »
This pretty much has to be a typo by "greaseflog". Integer is just an alias for LongInt... they're 100% the exact same thing all the time no matter what. Line 35 of objpas.pp:

Code: Pascal  [Select][+][-]
  1. Integer  = longint;

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #6 on: December 10, 2017, 12:53:27 am »
This pretty much has to be a typo by "greaseflog". Integer is just an alias for LongInt... they're 100% the exact same thing all the time no matter what. Line 35 of objpas.pp:

Code: Pascal  [Select][+][-]
  1. Integer  = longint;

Unless you are not in $mode delphi or $mode objfpc of course. Then integer is 2-byte.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #7 on: December 10, 2017, 02:49:59 am »
Unless you are not in $mode delphi or $mode objfpc of course. Then integer is 2-byte.
Partly true. That would result in a Error: Illegal type conversion: "SmallInt" to "TObject" (assuming TObject is really a System.TObject).

Assigning a LongInt to an Integer (or vise verse) seems to work for me without a complaining compiler... so, what exactly do i have to do to receive that infamous 'error' ?

Another reason to make me think it's a typo in error report is the use of result as well that it works for TS' colleagues.

Again, nothing can be said without having seen the actual declarations, preferably a complete example that can be compiled.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #8 on: December 10, 2017, 11:13:48 am »
Partly true. That would result in a Error: Illegal type conversion: "SmallInt" to "TObject" (assuming TObject is really a System.TObject).
But in that case you should not use a signed  integer type *at all*, molly.
Such code (with TObject) must be written using a PtrUint, which makes it also a little better to handle in other modes,since it returns a unsigned integer of SizeOf(Pointer) in any mode.

Using a signed integer type to use with an Object pointer is rather very old legacy for D5 and below compatibility.
« Last Edit: December 10, 2017, 11:17:25 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #9 on: December 11, 2017, 09:56:10 am »
@Thaddy:
yes, i am aware what is the problem there (and how to correct)  :)

I'm more interested to know how on earth i can generate the exact same error message as mentioned by OP. So far my attempts have failed  :(

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #10 on: December 11, 2017, 10:29:57 am »
I'm more interested to know how on earth i can generate the exact same error message as mentioned by OP. So far my attempts have failed  :(
The closest I came is below,
Try this on a 64bit system:
Code: Pascal  [Select][+][-]
  1. program testlonginterror;
  2.  
  3. uses classes;
  4. var
  5. l:TStringlist;
  6. T:longint;  //some unported object pointer a parameter or import
  7. begin
  8.   L:=TStringlist.Create;
  9.   L.AddObject('test',TObject(T));
  10.   L.Free;
  11. end.

We need some more code from OP.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Please help me - erro Illegal conversion type "LongInt" to "Integer"
« Reply #11 on: December 11, 2017, 10:44:18 am »
Thank you Thaddy.

That is the exact same code i used to try replicate the message from OP  :)

Still nothing about an error converting a Longint to an integer though. Because i've never seen that exact message before, i was interested to know how to produce it.

Because OP could use very strange code, e.g. function is named result, result is a local variable, TObject was redefined. Result is a custom class etc. it could be anything until OP shows some more code.
« Last Edit: December 11, 2017, 10:46:08 am by molly »

 

TinyPortal © 2005-2018