X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/94dd0df9f67acf39e8e85e44ade8021a98c417a1..2d2676149292e4e388bb102a41a3d64349ac88ed:/lmessages.pas

diff --git a/lmessages.pas b/lmessages.pas
index 0dc159b..a7bd01e 100755
--- a/lmessages.pas
+++ b/lmessages.pas
@@ -3,12 +3,22 @@
   which is included in the package
   ----------------------------------------------------------------------------- }
 
+//this unit provides a rough approximation of windows messages on linux
+//it is usefull for multithreaded applications on linux to communicate back to
+//the main lcore thread
+//This unit is *nix only, on windows you should use the real thing
+
 unit lmessages;
 //windows messages like system based on lcore tasks
 interface
 
 uses pgtypes,sysutils,bsearchtree,strings,syncobjs;
 
+
+{$if (fpc_version < 2) or ((fpc_version=2) and ((fpc_release < 2) or ((fpc_release = 2) and (fpc_patch < 2)) ))}
+  {$error this code is only supported under fpc 2.2.2 and above due to bugs in the eventobject code in older versions}
+{$endif}
+
 type
   lparam=taddrint;
   wparam=taddrint;
@@ -89,7 +99,7 @@ procedure init;
 
 implementation
 uses
-  baseunix,unix,lcore,unixutil;//,safewriteln;
+  baseunix,unix,lcore,unixutil,ltimevalstuff,sockets;//,safewriteln;
 {$i unixstuff.inc}
 
 type
@@ -125,7 +135,7 @@ var
   //than crash after over four billion
   //windows have been made ;)
   nextwindowhandle : qword = $100000000;
-{$i ltimevalstuff.inc}
+
 
 //findthreaddata should only be called while holding the structurelock
 function findthreaddata(threadid : integer) : tthreaddata;
@@ -399,11 +409,15 @@ begin
       //we have to get the window procedure while the structurelock
       //is still held as the window could be destroyed from another thread
       //otherwise.
-      windowproc := window.windowproc;
+      if window <> nil then begin
+        windowproc := window.windowproc;
+      end else begin
+        windowproc := nil;
+      end;
     finally
       structurelock.release;
     end;
-    if window <> nil then begin
+    if assigned(windowproc) then begin
       result := windowproc(lpmsg.hwnd,lpmsg.message,lpmsg.wparam,lpmsg.lparam);
     end else begin
       result := -1;
@@ -480,7 +494,7 @@ end;
 
 function PeekMessage(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): WINBOOL;
 begin
-  result := getmessageinternal(lpmsg,hwnd,wmsgfiltermin,wmsgfiltermax,PM_REMOVE,true);
+  result := getmessageinternal(lpmsg,hwnd,wmsgfiltermin,wmsgfiltermax,wRemoveMsg,true);
 end;
 
 function SetEvent(hEvent:THevent):WINBOOL;