Recent

Author Topic: Illegal type conversion: "ShortString" to "^C  (Read 7390 times)

WarLock

  • Guest
Illegal type conversion: "ShortString" to "^C
« on: October 10, 2005, 10:19:29 pm »
Hi i try to convert delphi 6 code to lazarus. when i compile the compile stop and give me this error
Illegal type conversion: "ShortString" to "^Char"
This source code line is the line
Result := SysUtils.StrLen(SysUtils.StrFmt(buffer, PChar(NewStr), args));

i have checked in the definition of error and this is what i got

Error: Illegal type conversion: ”arg1” to ”arg2”
When doing a type-cast, you must take care that the sizes of the variable and the destination type are the same.

Some one could point me what i making wrong ?
Thanks
Warlock

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: Illegal type conversion: "ShortString" to &quo
« Reply #1 on: October 11, 2005, 09:19:26 am »
Add {$mode delphi} of {$mode objfpc}{$H+} to your source. Then strings will be automatically ansistrings, like in Delphi and not shortstring like in Turbo Pascal.

WarLock

  • Guest
thanks it's working
« Reply #2 on: October 11, 2005, 10:44:30 am »
thanks you vincent thats compiling now
i have a other question

Code: [Select]
const MAX_ITEM_MODELS = 4;
type
   world_model         : array[0..MAX_ITEM_MODELS-1] of PChar;
end;


and in the same file after we have

Code: [Select]
const world_model: ( NULL, NULL, 0, 0 );
but lazarus stop when pasing the 3 arg

it's is ok to convert this to
Code: [Select]
const world_model: ( NULL, NULL, chr(0), chr(0) );
Thanks

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: thanks it
« Reply #3 on: October 11, 2005, 10:49:23 am »
I really don't understand where the nulls and 0 are coming from, they are not PChar, I would say.

I think I would write that code as:
Code: [Select]
const my_world_model= world_model : ( nil, nil, nil, nil );
Use correct syntax and use different identifiers for type and const declaration.

But without context, that is guessing.