Forum > General

[SOLVED] Thread => AlwaysWaitForExecute ?

<< < (4/4)

Fred vS:
Hello everybody.

I am extremely happy to announce that the challenge is done.  ;D

Marcus Sackrow find the solution =>


--- Code: ---> program progfpgui_graout;
>
> {$mode objfpc}{$H+}
>
> uses
>   {$IFDEF UNIX}
>   cthreads,
>   {$ENDIF}
>   SysUtils, Classes, fpg_base, fpg_main, fpg_form,
>   h_graout;
>
> type
>   Ttest = class(TfpgForm)
>   private
>   public
>     procedure AfterCreate; override;
>   end;
>   
>  type
>    TgraoutThread= class(TThread)
>   protected
>   procedure Execute; override;
>     public
>   constructor Create(CreateSuspended: boolean;
>       const StackSize: SizeUInt = DefaultStackSize);
> end;
>
> var
>  graoutThread : TgraoutThread;
>  libpath : string;
>
> constructor TgraoutThread.Create(CreateSuspended: boolean;
>   const StackSize: SizeUInt);
>   begin
>    inherited Create(CreateSuspended, StackSize);
>   FreeOnTerminate := true;
>     end;

>   procedure TgraoutThread.execute();
>   begin
>   graout_loadlib(libpath); /// load library and create thread
>   graout_mainproc();
>   graout_unloadlib();  // unload library
>   end;
>
> procedure Ttest.AfterCreate;
> begin
>   Name := 'test';
>   SetPosition(459, 222, 300, 250);
>   WindowTitle := 'I am the main program';
>  end;
>
> procedure MainProc;
> var
>   frm: Ttest;
>   begin
>     {$IFDEF Windows}
>   libpath := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'graout.dll' ;
>     {$else}

>   libpath := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'libgraout.so' ;
>    {$endif}
>   fpgApplication.Initialize;
>   try
>   graoutthread := TgraoutThread.create(true); // create the thread
>   
>   graoutthread.Start ;    /// run main graphical procedure of library via thread.execute
>   
>   frm := Ttest.Create(nil);  // create main form
>   fpgApplication.MainForm := frm;
>   frm.Show;
>   fpgApplication.Run;  // run main application
>   finally
>
>    frm.Free;
>   end;
> end;
>
> begin
>   MainProc;
> end.
--- End code ---

Using Pascal libraries, compiled in the "Java way", (only GCC and fpc can do that) opens Java to all the "traditional" native libraries (the main java-class load the fpc library and that fpc library load "classical native" libraries.)

Many thanks to everybody and eternal life to fpc.

Fre;D

Navigation

[0] Message Index

[*] Previous page

Go to full version