Re: [MSEide-MSEgui-talk] Some question about MSE thread...

2017-07-15 Thread Martin Schreiber
On Sunday 16 July 2017 00:04:48 Fred van Stappen wrote:
> Hello Martin
>
> Some question about MSE threads (tthreadcomp?)...
>
> Mainly how to convert fpc TThread into mse tthreadcomp...
>
> How do you convert this in mse code (+ some tips are welcome)?
>
>
> TMSEthread = class(TThread) >  TMSEthread = class(tthreadcomp) > ok
> ?
>
tthreadcomp is a container of teventthread which can be placed in a form.
In order to replace a FPC TThread one probably would use tmsethread or one of 
its descendants (tmutexthread -> tsemthread -> teventthread). tmutexthread 
has a mutex, tsemthread a semaphore and teventthread an event queue.

> constructor TMSEthread.Create(CreateSuspended: boolean;
>   const StackSize: SizeUInt) > ?
>
   constructor create(const athreadproc: threadprocty;
const afreeonterminate: boolean = false;
const astacksizekb: integer = 0); overload; virtual;

> destructor Destroy; override > ?
>
   destructor destroy; override;

> procedure Execute; override > ?
>
   function execute(thread: tmsethread): integer; virtual;

> procedure DoTerminate; override > ?
>
Does not exist, there is tthreadcomp.onterminate and tthreadcomp.onterminated.
> ...
>
> TMSEthread.Start > ?
>
tmsethread starts automatically, there is tthreadcomp.active.

> TMSEthread.Queue > ?
>
application.postevent(). Often application.lock()/unlock() is more convenient.

> TMSEthread.FreeOnTerminate := true > ?
>
tmsethread.freeonterminate:= true;

> TMSEthread.Priority := tpTimeCritical > ?

Not implemented.

> ...
>
> About using MSEThreads outside a MSE project...
> Is it possible?

Not easy, it needs the MSE-infrastructure.

Martin

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk


Re: [MSEide-MSEgui-talk] TSlider and onmouseevent/onkeydown/onkeyup ?

2017-07-15 Thread Martin Schreiber
On Saturday 15 July 2017 18:38:28 Fred van Stappen wrote:
> > In order to trigger value settings before releasing the mouse button
> > activate .scrollbar.options sbo_thumbtrack (default true).
>
> Yep, perfect, I get exactly what I want, thanks.
>
> > For the the problem with the thread I would do
>
> Oooops, that is much more complicated than using:
> "onmouseevent" + "onkeyup" + "onkeydown" with "Slider1.tag := 0 (or 1);".
>
You need to call application.lock()/unlock() or use another synchronizing 
mechanism while accessing main thread elements from a worker thread or there 
will be problems (most likely crashes) sooner or later. How do you protect 
gui resources in your code?

"
   if not tslider1.clicked then begin
"
replaces your 
"
procedure ASlider.onmousedown(sender: TObject); // idem for onkeydown
begin
ASlider.tag := 1;
end;

procedure ASlider.onmouseup(sender: TObject); // idem for onkeyup
begin
ASlider.tag := 0;
end;

and in the loop of the thread:

...
if ASlider.tag = 0 then ASlider.position := somewhere;
"
why do you think it is "much more complicated"? your code has nine lines, mine 
only one and doesn't need event properties. The code I showed is a working 
example of a 0..1.0 loop in a thread in order to 
demonstrate "tslider1.clicked",

> Also I use in a unit a fpc TThread (not a tthreadcomp), so your code is not
> compatible... And where/when to use that procedure?
>
application.lock()/unlock() and .clicked can be used everywhere.

Martin

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk


[MSEide-MSEgui-talk] Some question about MSE thread...

2017-07-15 Thread Fred van Stappen
Hello Martin

Some question about MSE threads (tthreadcomp?)...

Mainly how to convert fpc TThread into mse tthreadcomp...

How do you convert this in mse code (+ some tips are welcome)?


TMSEthread = class(TThread) >  TMSEthread = class(tthreadcomp) > ok ?

constructor TMSEthread.Create(CreateSuspended: boolean;
  const StackSize: SizeUInt) > ?

destructor Destroy; override > ?

procedure Execute; override > ?

procedure DoTerminate; override > ?

...

TMSEthread.Start > ?

TMSEthread.Queue > ?

TMSEthread.FreeOnTerminate := true > ?

TMSEthread.Priority := tpTimeCritical > ?
...

About using MSEThreads outside a MSE project...
Is it possible?
If yes, tips are welcome.

Thanks.

Fre;D

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk


Re: [MSEide-MSEgui-talk] TSlider and onmouseevent/onkeydown/onkeyup ?

2017-07-15 Thread Fred van Stappen
> In order to trigger value settings before releasing the mouse button activate 
> .scrollbar.options sbo_thumbtrack (default true).

Yep, perfect, I get exactly what I want, thanks.

> For the the problem with the thread I would do

Oooops, that is much more complicated than using:
"onmouseevent" + "onkeyup" + "onkeydown" with "Slider1.tag := 0 (or 1);".

Also I use in a unit a fpc TThread (not a tthreadcomp), so your code is not 
compatible...
And where/when to use that procedure?

OK, I keep your solution in mind (but I will still use, for the moment, the 
custom TSlider published "onmouseevent" + "onkeyup" + "onkeydown").
This because, after hours of using it, I get absolutely what I want, without 
any problem.

(Huh, what could be wrong with that published "onmouseevent" + "onkeyup" + 
"onkeydown" ?)

Thanks Martin.

Fre;D

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk


Re: [MSEide-MSEgui-talk] TSlider and onmouseevent/onkeydown/onkeyup ?

2017-07-15 Thread Fred van Stappen

Hello Martin.


OK, I will (try to) understand all your advices.


Write you later.


Fre;D


De : Martin Schreiber 
Envoyé : samedi 15 juillet 2017 08:26
À : mseide-msegui-talk@lists.sourceforge.net
Objet : Re: [MSEide-MSEgui-talk] TSlider and onmouseevent/onkeydown/onkeyup ?

On Friday 14 July 2017 18:21:16 Fred van Stappen wrote:
>
> Other thing...
>
> When manually changing the position of the slider, how to get the position
> of the slider before to release the mouse-button ?
>
> I did try with Tslider.onchange but the position does not change until the
> button is released.
>
All MSEgui editwidgets (including tslider) have the
properties "onsetvalue", "ondataentered" and "onchange".
"onsetvalue" will be called when the user enters a value. In case of tslider
the signature is
"
procedure tmainfo.slidersetvalev(const sender: TObject; var avalue: realty;
   var accept: Boolean);
"
"avalue" is the new value, ".value" still has the old value. Here the
new value can be changed by changing "avalue" or be rejected by
setting "accept" to false.
If the new value has been accepted   will be set to the new
value and "ondataentered" will be called. "ondataentered" has the signature
"
procedure tmainfo.sliderdatentev(const sender: TObject);
"
"onchange" will be called when the "value" changes. "onchange" has the
signature
"
procedure tmainfo.sliderchangeev(const sender: TObject);
"
In order to trigger value settings before releasing the mouse button activate
.scrollbar.options sbo_thumbtrack (default true).

I do not like to publish mouse events because this events are used internally
by tslider and are not intended to be used by the component users.

For the the problem with the thread I would do
"
procedure tmainfo.threadexeev(const sender: tthreadcomp);
var
 val1: realty;
begin
 val1:= 0;
 while true do begin
  sleep(100);
  if sender.terminated then begin
   break;
  end;
  val1:= val1 + 0.01;
  if val1 > 1.001 then begin
   break;
  end;
  try
   application.lock();
   if not tslider1.clicked then begin
tslider1.value:= val1;
   end;
  finally
   application.unlock();
  end;
 end;
end;

"
Martin

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk