PDA

View Full Version : SDL on Delphi XE2



kotai
05-06-2012, 12:47 AM
Hi.

I'm installed DelphiXE2 and SDL-JEDI but when I compile my games have a SDL.pas error :


[DCC Error] sdl.pas(358): E2029 Identifier expected but 'CONST' found

I solved my problem by adding the following to the jedi-sdl.inc file:



{$IFDEF ver230}
{$DEFINE Delphi} {Delphi XE2}
{$DEFINE Delphi32}
{$DEFINE Delphi4UP}
{$DEFINE Delphi5UP}
{$DEFINE Delphi6UP}
{$DEFINE Delphi7UP}
{$DEFINE Delphi8UP}
{$DEFINE Delphi9UP}
{$DEFINE Delphi10UP}
{$DEFINE Delphi11UP}
{$DEFINE Delphi12UP}
{$DEFINE Delphi14UP}
{$DEFINE Delphi15UP}
{$DEFINE Delphi16UP}
{$WARN UNSAFE_TYPE OFF} {Disable warning for unsafe types in Delphi 7}
{$DEFINE Has_Int64}
{$DEFINE HAS_TYPES}
{$ENDIF ver210}


Now game compile but no load BMP, PNG or WAV files:


Graphic := SDL_LoadBMP( PChar( sFile ) );

Graphic:= IMG_Load( PChar( sFile ) );

Sound := Mix_LoadWAV( PChar( sFile ) );

Allways return NIL. No error, but no load. Same code in Delphi2006 work OK.

What's going on here?

Thanks :)

Super Vegeta
05-06-2012, 03:13 AM
Looking at my sdl.pas, I guess that the compiler got uses, but then went trough all the {$IFDEF}s and didn't specify anything to use, going straight to const, hence the "identifier expected". Maybe try {$DEFINE WINDOWS} (since it's Delphi)?

Sascha Willems
05-06-2012, 04:59 AM
The problem might be unicode-releated. You pass strings as PChars, but since XE2 is unicode, a char now has a size of 2 Bytes (codepage + char) instead of 1 Byte that it had in earlier versions. So try to pass the filenames different, e.g. cast as ansistring or some type where char size is 1, which SDL obviously expects.

Some more explanation : Since a Char in Uncide now has two bytes, for SDL your filename will look like this : "M Y F I" instead of "MyFile" due to codepages being stored with each char.

So you'll e.g. have to do something like this : Graphic := SDL_LoadBMP(PAnsiChar(sFile)), depending how sFile is declared.

kotai
05-06-2012, 09:53 AM
I solve it

I change all PChar(xxx) for PChar(AnsiString(xxx)) and now work Ok.

Thanks.

kotai
11-06-2012, 11:58 AM
Hi again.

Now I can compile my projects in Win32 and Win64, but I like port to iOS and MacOSx.

Mac OSx
When I active Platform OSx I have this error in SDL.pas:


[DCC Fatal Error] sdl.pas(318): F1026 File not found: 'Windows.dcu'

317 {$IFDEF WINDOWS}
318 Windows;
319 {$ENDIF}


I'm compile for platform OSx but compiler think I'm compile to Windows.
How I can tell compiler that I am compiling for Mac OSx and not for Windows ?


iOS

When you select iOS and export to Xcode, game is compiled for Xcode in Mac by FPC 2.6.0 and I need SDL.pas in Mac.
When install in Mac "fpc-2.6.0.intel-macosx.pkg" from "FireMonkey-iOS.dmg" image, JEDI-SDL has installed in:


/Developer/Embarcadero/fpc/packages/sdl

but I do not know how add library path to use it when compile with Xcode.
Is there something like "Library" of Delphi where you can indicate paths for search *. pas ?

For test, I copy SDL.pas from "/Developer/Embarcadero/fpc/packages/sdl/src/SDL.pas" to my project folder but I have next error:

Target OS: Darwin/iPhoneSim fro i386
Compiling /Users/...../Naves.pas
Compiling /Users/...../sdl.pas
Fatal: Can't find unit x used by sdl
Fatal: Compilation aborted


I think problem is at line 311 of sdl.pas:

300{$IFDEF UNIX}
301 {$IFDEF FPC}
302 pthreads,
303 unixtype,
304 baseunix,
305 {$IFNDEF GP2X}
306 unix,
307 {$ELSE}
308 unix;
309 {$ENDIF}
310 {$IFNDEF GP2X}
311 x,
312 xlib;
313 {$ENDIF}
314 {$ELSE}
315 Libc,
316 Xlib;
317 {$ENDIF}
318{$ENDIF}



Compiler think I'm compile for GP2x ?
How I can tell compiler that I am compiling for iOS and not for GP2X ?

Thanks.

Stoney
11-06-2012, 05:18 PM
The SDL headers are not really optimized for Delphi XE2 and I think for it to work on Mac OS X, you will to tweak a few compiler conditions in JEDI-SDL.inc. If I remember correctly, if compiled with Delphi on desktop machines, it assumes Windows is used as its platform.

With SDL 1.2 on iOS you have two problems:
- SDL 1.2 does not work on iOS, you need SDL 1.3/2.0 (try these headers: https://github.com/Stoney-FD/sdl13-pascal <-- They worked for me in the past (Disclaimer: I wrote them), but are pretty much alpha, if not pre-alpha)
- You can't link against dynamic libraries

kotai
12-06-2012, 08:41 AM
Thanks for reply.

¿ SDL in iOS can't link against dynamic libraries ?
I download by mercurial SDL2.0 from http://hg.libsdl.org/SDL and I build in xcode file library "libSDL2.a"
¿ I can't work like windows and put in project folder the library "libSDL2.a" ?

If I can't complile for MacOS, no problem, but I like port my games to iOS.

Have you a small example in free pascal for test SDL in iOS ?

Thanks.

Micronix-TRSI
15-01-2013, 10:16 PM
SDL x86_x64 with Header for Delphi Version > 4 und Lazarus 9.30.4 !

kotai
16-01-2013, 09:59 AM
Thanks for SDL64bits.
I test it this week.

Kotai.