Re: [Lazarus] TTimer woes (newbie)

2014-04-01 Thread Michael Schnell

On 03/31/2014 07:51 PM, Flávio Etrusco wrote:


TTimer in Windows (and the basic timer support in Windows ) is 
implemented using window messages and you're not allowing the app to 
process messages inside your loop.


This necessity is not limited to Windows nor to TTimer.


Any Object Pascal Event handler (hence most code done in normal 
projects) is driven by the Project's Event Queue (which in Windows in 
turn is driven by Windows messages).


In fact using Application.ProcessMessages in a loop is a workaround 
that is necessary when you really need a long winding loop in one of the 
(main Thread-) - Events) calculating something.


It is a lot better style to do short events, whenever possible (maybe 
doing the long winding stuff in a TThread). Infinite (polling) loops in 
fact are (close to) forbidden, as they eat up CPU cycles that can better 
be used for other activities in the project or in any other program 
running on that PC.


In fact Bob is not doing this (eating up CPU Cycles), but he uses 
wait(), which only hampers it's own project. This also usually is (close 
to) forbidden in the main thread, as the GUI will stop working while the 
main thread waits.


Thus he should either use a TTimer instead of waiting and continue the 
work to be done in a newly entered Timer Event, or execute the code that 
includes the wait() in a TThread.


-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TTimer woes (newbie)

2014-04-01 Thread Howard Page-Clark

On 01/04/2014 09:44, Michael Schnell wrote:


In fact Bob is not doing this (eating up CPU Cycles), but he uses
wait(), which only hampers it's own project.


Actually Bob's wait uses his own TTimer-based code, and is not well 
designed.
As Flavio wrote, he would be best to replace all his waits with a Sleep, 
and remove his timer altogether.


Howard


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Better implementation of GetTickcount using clock_gettime

2014-04-01 Thread Luca Olivetti
I use GetTickCount a lot to keep track of timeouts.
On windows, it is guaranteed to be monotonic, so my usual

  if GetTickCount-StartTimeTimeout then..

works fine (yes, even when the time wraps around, provided StartTime is
defined as DWORD and Timeout is smaller than a DWORD, of course I could
use GetTickCount64 but usually the 32bits version is enough).

For unix the implementation uses fpgettimeofday but that's not
monotonic, so it could break the above code.

For linux a more accurate implementation could be

function GetTickCount64: QWord;
var
  tp: timespec;
begin
  clock_gettime(CLOCK_MONOTONIC, @tp);
  Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_nsec div 100);
end;


And I say linux because CLOCK_MONOTONIC is only defined there in fpc,
though it should be available even in other systems:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html

Bye
-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es
Tel. +34 935883004  Fax +34 935883007

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Better implementation of GetTickcount using clock_gettime

2014-04-01 Thread zeljko

On 04/01/2014 12:20 PM, Luca Olivetti wrote:


For linux a more accurate implementation could be

function GetTickCount64: QWord;
var
   tp: timespec;
begin
   clock_gettime(CLOCK_MONOTONIC, @tp);
   Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_nsec div 100);
end;


And I say linux because CLOCK_MONOTONIC is only defined there in fpc,
though it should be available even in other systems:


CLOCK_MONOTONIC is available only for kernels = 2.6.26.

zeljko


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Better implementation of GetTickcount using clock_gettime

2014-04-01 Thread Henry Vermaak
On Tue, Apr 01, 2014 at 12:45:54PM +0200, zeljko wrote:
 On 04/01/2014 12:20 PM, Luca Olivetti wrote:
 
 For linux a more accurate implementation could be
 
 function GetTickCount64: QWord;
 var
tp: timespec;
 begin
clock_gettime(CLOCK_MONOTONIC, @tp);
Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_nsec div 100);
 end;
 
 
 And I say linux because CLOCK_MONOTONIC is only defined there in fpc,
 though it should be available even in other systems:
 
 CLOCK_MONOTONIC is available only for kernels = 2.6.26.

No, it's been around since before 2.6.

Henry

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Better implementation of GetTickcount using clock_gettime

2014-04-01 Thread zeljko

On 04/01/2014 01:57 PM, Henry Vermaak wrote:

On Tue, Apr 01, 2014 at 12:45:54PM +0200, zeljko wrote:

On 04/01/2014 12:20 PM, Luca Olivetti wrote:


For linux a more accurate implementation could be

function GetTickCount64: QWord;
var
   tp: timespec;
begin
   clock_gettime(CLOCK_MONOTONIC, @tp);
   Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_nsec div 100);
end;


And I say linux because CLOCK_MONOTONIC is only defined there in fpc,
though it should be available even in other systems:


CLOCK_MONOTONIC is available only for kernels = 2.6.26.


No, it's been around since before 2.6.


You're right. I've been on CLOCK_MONOTONIC_RAW which is available since 
2.6.28 actually  so my complete information was wrong ;)


zeljko


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TTimer woes (newbie)

2014-04-01 Thread Paul Breneman

On 03/31/2014 01:51 PM, Flávio Etrusco wrote:
...

I guess simply changing your loop to:
+++
repeat
   Application.ProcessMessages;
until not timer1.enabled;
+++
should make it work.


That loop will work, but the CPU usage will be 100% and the CPU will run 
warm and the battery life on a laptop will be bad.  I'd normally add a 
Sleep(10) in the loop to avoid those problems.


Best regards,
Paul
www.TurboControl.com


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] LazOpenGLContext won't install

2014-04-01 Thread Anthony Tekatch

I am using version 1.2~rc2+dfsg-1 and get the following error when trying
to install the LazOpenGLContext 0.0.1 package then Save and Rebuild IDE:

  (1,1) Fatal: Can not find unit lazopenglcontext used by Lazarus. Check if 
package LazOpenGLContext is in the dependencies.


What steps are required to install the lazopenglcontext package? Or is
there a more up-to-date method of getting 3D display in a Lazarus
application?

Thanks,
Anthony

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LazOpenGLContext won't install

2014-04-01 Thread Mattias Gaertner
On Tue, 1 Apr 2014 12:27:41 -0400
Anthony Tekatch anth...@unihedron.com wrote:

 
 I am using version 1.2~rc2+dfsg-1

We don't provide such a version. Where did you get that? How did you
install Lazarus?
Do you use gtk1 or gtk2?
What fpc version do you use?

 and get the following error when trying
 to install the LazOpenGLContext 0.0.1 package then Save and Rebuild IDE:
 
   (1,1) Fatal: Can not find unit lazopenglcontext used by Lazarus. Check if 
 package LazOpenGLContext is in the dependencies.
 
 
 What steps are required to install the lazopenglcontext package? Or is
 there a more up-to-date method of getting 3D display in a Lazarus
 application?

It works fine for me under Linux/gtk2.

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LazOpenGLContext won't install

2014-04-01 Thread Anthony Tekatch
On Tue, 1 Apr 2014 18:46:26 +0200, Mattias Gaertner nc-gaert...@netcologne.de 
wrote:

 On Tue, 1 Apr 2014 12:27:41 -0400
 Anthony Tekatch anth...@unihedron.com wrote:
 
  I am using version 1.2~rc2+dfsg-1
 
 We don't provide such a version. Where did you get that? How did you
 install Lazarus?

From the Debian testing repository.


 Do you use gtk1 or gtk2?

gtk2


 What fpc version do you use?

2.6.2


  and get the following error when trying
  to install the LazOpenGLContext 0.0.1 package then Save and Rebuild
  IDE:
  
(1,1) Fatal: Can not find unit lazopenglcontext used by Lazarus.
  Check if package LazOpenGLContext is in the dependencies.
  
  
  What steps are required to install the lazopenglcontext package? Or is
  there a more up-to-date method of getting 3D display in a Lazarus
  application?
 
 It works fine for me under Linux/gtk2.


Thank you for your reply. 

What version/source of Lazarus do you suggest that I use (which has a
working LazOpenGLContext package)?

Thanks,
Anthony


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Better implementation of GetTickcount using clock_gettime

2014-04-01 Thread Mattias Gaertner
On Tue, 01 Apr 2014 12:20:53 +0200
Luca Olivetti l...@wetron.es wrote:

[...]
 function GetTickCount64: QWord;
 var
   tp: timespec;
 begin
   clock_gettime(CLOCK_MONOTONIC, @tp);
   Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_nsec div 100);
 end;
[...]

Thanks. GetTickCount64 now uses it on Linux.

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Better implementation of GetTickcount using clock_gettime

2014-04-01 Thread Luca Olivetti
El 01/04/14 20:03, Mattias Gaertner ha escrit:
 On Tue, 01 Apr 2014 12:20:53 +0200
 Luca Olivetti l...@wetron.es wrote:
 
 [...]
 function GetTickCount64: QWord;
 var
   tp: timespec;
 begin
   clock_gettime(CLOCK_MONOTONIC, @tp);
   Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_nsec div 100);
 end;
 [...]
 
 Thanks. GetTickCount64 now uses it on Linux.

Wow, that was fast. Thank you.

Bye
-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es
Tel. +34 935883004  Fax +34 935883007

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LazOpenGLContext won't install

2014-04-01 Thread Mattias Gaertner
On Tue, 1 Apr 2014 13:57:57 -0400
Anthony Tekatch anth...@unihedron.com wrote:

[...]

 What version/source of Lazarus do you suggest that I use (which has a
 working LazOpenGLContext package)?

See here:
http://wiki.lazarus.freepascal.org/Getting_Lazarus

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LazOpenGLContext won't install

2014-04-01 Thread Anthony Tekatch
On Tue, 1 Apr 2014 20:10:03 +0200, Mattias Gaertner nc-gaert...@netcologne.de 
wrote:

 On Tue, 1 Apr 2014 13:57:57 -0400
 Anthony Tekatch anth...@unihedron.com wrote:
 
  What version/source of Lazarus do you suggest that I use (which has a
  working LazOpenGLContext package)?
 
 See here:
 http://wiki.lazarus.freepascal.org/Getting_Lazarus


That did the trick. I installed from the Debian binaries there.

Thanks!

Anthony
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Prevent visual updates

2014-04-01 Thread Chris Crori

That is a great idea Mattias!
a timer with 1 as interval is fast enough for responce application and 
slow enough to avoid flickering


Thanks!

-Αρχικό μήνυμα- 
From: Mattias Gaertner

Sent: Sunday, March 30, 2014 11:17 PM
To: lazarus@lists.lazarus.freepascal.org
Subject: Re: [Lazarus] Prevent visual updates

On Sun, 30 Mar 2014 23:11:41 +0300
Chris Crori cror...@yahoo.com wrote:


Doublebuffered did not solve my problem
i have a panel that i make visible depending on a flag. in a unique
situation, this flag must change 2 times, so it's my bad, not the LCL's
if i could disable the LCL messages in that unique situation, it would be
very helpfull, but if i can't do that, i m sure i ll find another way


Hide/Show the panel on Idle or via a Timer.

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Prevent visual updates

2014-04-01 Thread Martin Frb

On 01/04/2014 20:43, Chris Crori wrote:

That is a great idea Mattias!
a timer with 1 as interval is fast enough for responce application 
and slow enough to avoid flickering


Another very good way to do this, is using Application.QueueAsync

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Prevent visual updates

2014-04-01 Thread Chris Crori

QueueAsync. Thread safe and multiplatform...
I will look into that Martin, seems like a solution to many problems

Thank you!


-Αρχικό μήνυμα- 
From: Martin Frb

Sent: Tuesday, April 01, 2014 11:12 PM
To: Lazarus mailing list
Subject: Re: [Lazarus] Prevent visual updates

On 01/04/2014 20:43, Chris Crori wrote:

That is a great idea Mattias!
a timer with 1 as interval is fast enough for responce application and 
slow enough to avoid flickering


Another very good way to do this, is using Application.QueueAsync

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Prevent visual updates

2014-04-01 Thread Chris Crori

QueueAsync works great! Martin you rock! ;)

-Αρχικό μήνυμα- 
From: Chris Crori

Sent: Wednesday, April 02, 2014 1:07 AM
To: Lazarus mailing list
Subject: Re: [Lazarus] Prevent visual updates

QueueAsync. Thread safe and multiplatform...
I will look into that Martin, seems like a solution to many problems

Thank you!


-Αρχικό μήνυμα- 
From: Martin Frb

Sent: Tuesday, April 01, 2014 11:12 PM
To: Lazarus mailing list
Subject: Re: [Lazarus] Prevent visual updates

On 01/04/2014 20:43, Chris Crori wrote:

That is a great idea Mattias!
a timer with 1 as interval is fast enough for responce application and 
slow enough to avoid flickering


Another very good way to do this, is using Application.QueueAsync

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus