Recent

Author Topic: [SOLVED] Thread => AlwaysWaitForExecute ?  (Read 7483 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 1675
    • miXimum is the DJ's best friend
Re: Thread => AlwaysWaitForExecute ?
« Reply #15 on: January 05, 2015, 04:44:35 pm »
Hello everybody.

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

Marcus Sackrow find the solution =>

Code: [Select]
> 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.

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
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs