PDA

View Full Version : Problem while porting string code to FPC



chronozphere
08-05-2010, 07:45 PM
Hey,

I've been trying to get some code working with FPC, however it chokes on the following line:


procedure TNashaLogger.Write(aLogStr: String);
begin
FLog.Add(aLogStr);

{$IFDEF MSWINDOWS}
OutputDebugString( PChar(aLogStr) ); << HERE
{$ENDIF}
end;




G:\n3d\workingdir\src\n3d_log.pas(91,22) Error: Illegal type conversion: "ShortString" to "^Char"


Does the keyword String refer to a shortstring in FPC?

I have placed the following at the top of my unit:

{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}


But it doesn't really help. Can anyone tell me what I can do to fix this?

I would be really thankfull if someone gave me an article that helps you port delphi code to FPC. Especially the small differences in functionality, strings, types etc would be good to know about. :)

Thanks in advance.

paul_nicholls
08-05-2010, 10:13 PM
Try this at the top of your unit(s):

{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
{$H+}

H+ is to turn long strings on by default, see if this helps :)

cheers,
Paul

chronozphere
08-05-2010, 10:20 PM
Thanks paul.. that works. :)

WILL
09-05-2010, 11:01 PM
If you are using Lazarus you can set it in your Compiler options by going (in your menu) to Project -> Compiler Options... then go into your 'Parsing' tab and under Syntax Mode (-M) choose Delphi.

I do this in each of my own projects and it works quite well when using Delphi-style syntax.