Hi all. Im studying Threads. I tried to run some examples but one i didnt get.
This example ok:
Code:
uses
SDL;
{$APPTYPE CONSOLE}
var
thread: PSDL_Thread;
returnValue: Integer;
function thread_func(): Integer;
begin
// do threading here
WriteLn('Start Thread');
SDL_Delay(5000);
WriteLn('End Thread');
result := 1; // thread leaves and return this value
end;
begin
returnValue := 0;
thread := SDL_CreateThread(@thread_func, NIL);
SDL_WaitThread(thread, returnValue);
WriteLn('Thread returns code ',returnValue);
SDL_Quit;
WriteLn('ByeBye ;)');
end.
But this, i get error. why? What is wrong? This example I ported from Lazy Foo's tutorial.
Code:
program teste;
{$APPTYPE CONSOLE}
uses
sdl,
sdlutils,
sdl_image;
const
SCREEN_WIDTH = 640;
SCREEN_HEIGHT = 480;
SCREEN_BPP = 32;
var
screen,image: PSDL_Surface;
event: TSDL_Event;
thread: PSDL_Thread;
quit: boolean = false;
function load_image(filename: string; setcolorkey: boolean) : PSDL_Surface; overload;
var
optimizedImage, loadedImage: PSDL_Surface;
r,g,b: uint8;
begin
loadedImage := IMG_Load(pchar(filename));
if (loadedImage <> nil) then
begin
optimizedImage := SDL_DisplayFormat(loadedimage);
SDL_FreeSurface(loadedimage);
if (optimizedImage <nil> 0) do
begin
case event.type_ of
SDL_QUITEV:
quit:= true;
end;
end;
clean_up;
end;
end.
Sorry my english.
Bookmarks