Re: [Lazarus] Enqueuing a callback from a thread via other class - or am I overcomplicating this ?

2017-06-20 Thread Lukasz Sokol via Lazarus
On 19/06/17 10:05, Lukasz Sokol via Lazarus wrote:
> On 19/06/17 00:30, José Mejuto via Lazarus wrote:
>> El 18/06/2017 a las 22:44, el es via Lazarus escribió:
>>
>>> Hence the object, would have to have ITS callback routine be something like 
>>> a TNotifyEvent ( procedure(AObject: TSomeObject) of object, or something), 
>>> and the flag set is set when the callback returns to the object context like
>>>
>>> procedure TSomeObject.Callback;
>>> // this procedure is enQueue()d by the thread
>>> begin
>>>if Assigned({Self.}FSomeObjectNotifyEvent) then
>>>  FSomeObjectNotifyEvent(Self);
>>
>> Hello,
>>
>> Just exit the procedure and there is not free problem. You will get an 
>> exception when you use object data, not object code.
>>
> 
> I did now, and also, beforehands I did not have the TSomeObjectNotifyEvent() 
> type of callback...
> so in the callback I had to browse through the list of TSomeObject's, 
> searching for the right one - and that was really risky;
> 
> 
> 
>>
>> procedure TSomeObject.Callback;
>> // this procedure is enQueue()d by the thread
>> begin
>>if Assigned({Self.}FSomeObjectNotifyEvent) then
>>  FSomeObjectNotifyEvent(Self);
>>Self.CanBeDestroyed := true;
>>Exit;
>> end;
>>
>> After you set CanBeDestroyed to true you must consider all data as RANDOM, 
>> so don't access any property or variable.
>>
> Understood, I ensured there is nothing accessing the TSomeObject sent as Self 
> to the event handler, after it comes back.
> 

I also had dual-usage of the TSomeObjects: sometimes, they were supposed to be 
'just' processed by the thread and then discarded,
some were supposed to be with callback to the main thread;

But I was still hitting the F0F0F0F0 when the above was being queued, when 
FSomeObjectNotifyEvent was nil;

So actually, I had to move the (equivalent of)

SomeObject.CanBeDestroyed := true;

to be the very last call of the  FSomeObjectNotifyEvent(Self) handler, in the 
main thread,
to handle the ones with callback (enclosed in finally...end),

and in the worker thread, to only Queue() the callbacks if the handler is 
subscribed to:

if Assigned(SomeObject.FSomeObjectNotifyEvent) then
  Queue(SomeObject.FSomeObjectNotifyEvent);

> Thanks,
> 
> -L.



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


Re: [Lazarus] Enqueuing a callback from a thread via other class - or am I overcomplicating this ?

2017-06-19 Thread Lukasz Sokol via Lazarus
On 19/06/17 00:30, José Mejuto via Lazarus wrote:
> El 18/06/2017 a las 22:44, el es via Lazarus escribió:
> 
>> Hence the object, would have to have ITS callback routine be something like 
>> a TNotifyEvent ( procedure(AObject: TSomeObject) of object, or something), 
>> and the flag set is set when the callback returns to the object context like
>>
>> procedure TSomeObject.Callback;
>> // this procedure is enQueue()d by the thread
>> begin
>>if Assigned({Self.}FSomeObjectNotifyEvent) then
>>  FSomeObjectNotifyEvent(Self);
> 
> Hello,
> 
> Just exit the procedure and there is not free problem. You will get an 
> exception when you use object data, not object code.
> 

I did now, and also, beforehands I did not have the TSomeObjectNotifyEvent() 
type of callback...
so in the callback I had to browse through the list of TSomeObject's, searching 
for the right one - and that was really risky;



> 
> procedure TSomeObject.Callback;
> // this procedure is enQueue()d by the thread
> begin
>if Assigned({Self.}FSomeObjectNotifyEvent) then
>  FSomeObjectNotifyEvent(Self);
>Self.CanBeDestroyed := true;
>Exit;
> end;
> 
> After you set CanBeDestroyed to true you must consider all data as RANDOM, so 
> don't access any property or variable.
> 
Understood, I ensured there is nothing accessing the TSomeObject sent as Self 
to the event handler, after it comes back.


> Remember that creating and destroying threads is very expensive in CPU time.
> 

There is only 2 statically defined threads in the entire application :) 

one is the GUI thread (the Application, aka main thread)

and the other is the TSomeObject life handler 
(you could call it a queue of objects to be processed and returning results 
from hardware communication)

Thanks,

-L.




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


Re: [Lazarus] Enqueuing a callback from a thread via other class - or am I overcomplicating this ?

2017-06-14 Thread Lukasz Sokol via Lazarus
On 14/06/17 11:33, Mattias Gaertner via Lazarus wrote:
> On Wed, 14 Jun 2017 11:12:11 +0100
> Lukasz Sokol via Lazarus <lazarus@lists.lazarus-ide.org> wrote:
> 
>> [...]
>>   SomeClassLockedList := SomeClassList.LockedList; // there are 
>> try/excepts around all here, but did not want to muddle the picture
>>   Queue(TSomeClass(SomeClassLockedList.Items[i]).Processed); 
> 
> Queue(@TSomeClass(SomeClassLockedList.Items[i]).Processed);
>   ^
> 
> Mattias
> 

Thanks! looks so easy in hindsight ;) same the callbacks need to be assigned 
with the @ in front :)

-L.

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


[Lazarus] Enqueuing a callback from a thread via other class - or am I overcomplicating this ?

2017-06-14 Thread Lukasz Sokol via Lazarus
Hi,

I have a TThread, that processes a T(Thread)List of TSomeClass objects 
continuously.

I want to have a callback in the TSomeClass, to which another class can put 
their procedure to call into,
but the callback needs to be 'thread safe' (because it can be accessed (read) 
by GUI related elements).

I tried like this:

TSomeClass = class

private
... // other variables/fields
public
  class var ProcessedCallback : TThreadMethod;
  var
   ... //other variavbles

  procedure Processed;
end;

procedure TSomeClass.Processed;
begin
  if Assigned(ProcessedCallback) then 
ProcessedCallback();
  
end;


and in the TMyThread I am trying to do

var SomeClassList : TThreadList; // is declared private to the thread - only 
the thread manages the lifetime of the list members

procedure TMyThread.Execute;
var 
SomeClassLockedList: TList;
begin
  i := 0;
  while not Terminated do
begin
  if SomeClassList.Count = 0 then 
  begin
sleep(10);  
continue;
  end;
  SomeClassLockedList := SomeClassList.LockedList; // there are try/excepts 
around all here, but did not want to muddle the picture
  Queue(TSomeClass(SomeClassLockedList.Items[i]).Processed); 
  // but above here I'm getting an error : got 'untyped', expected 
'procedure variable type of object;Register'.
  SomeClassList.UnlockList;
  i := i+1;
end;
  
end;

// the above sort-of gives the gist of what I'm trying to achieve

What am I doing wrong ? 
Does the procedure to be enqueued have to be declared in the TThread header ?

Hope some of it makes (any) sense ...

Thanks in advance,

-L.

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


[Lazarus] TTimer(s) & strange resize/move form interaction in Win10 with Win32 application ?

2017-04-27 Thread Lukasz Sokol via Lazarus
I have a Win32 application that I compile either on 

Lazarus 1.4.4 r49931 FPC 2.6.4 i386-win32-win32/win64
 (under WinXP SP3)


Lazarus 1.6.2 r53354 FPC 3.0.0 x86_64-win64-win32/win64 (under Win10) (actually 
also downloaded fpc-3.0.2.i386-win32.exe
from Hungarian mirror (as of 27/04/2017 ~12:00 GMT) for my application loads a 
32bit library and refused to do it when built for 64bit target)

It runs, it loads, it works. On windows XP under debugger in Lazarus, no 
problem.

When I copy the executable made under WinXP to the Win10, 64bit computer, it 
also works;

(only if I want to recompile it under Win10 I have to do it with 32bit target 
compiler).

But, both copied AND the recompiled version, under Win10 has the following 
behavior:

- I can click any buttons I have on the form, change size of the entire form, 
move dividers etc,
but only until 2 TTimers are not active (they tick in about 10 and 20ms 
independent of each other
and update 2 different sets of TLabels on the form, just about)

But when I try to move the form, or resize it by the external edges, WITH the 2 
TTimers running, 
the form 'sort of' freezes: 
sort-of, because the TLabels are still updated by my TTimers' OnTimer events 
running,
but clicking buttons has no effect, I can't resize the dividers any more, and 
the form would not even move
when dragged by the title bar. 

This happens from the onset of just clicking on the title bar, or clicking the 
edge of form when 
mouse pointer changes to 'two arrows'.

If I stop the running TTimers, I can move and resize and click anything;

Also when the form 'freezes' I can not click away from it - I have to use 
Alt+TAB to switch to another window,
and kill it externally (through Task Manager) otherwise it will not yield.

This (as I wrote above) does not happen on a 32bit computer under WinXP SP3.

Hope it helps,
Kind Regards
Lukasz

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


Re: [Lazarus] Startup environment: to Gui, or not to GUI? [OT]

2017-04-12 Thread Lukasz Sokol via Lazarus
On 11/04/17 19:44, Mark Morgan Lloyd via Lazarus wrote:
[...]
> 
> Regrettably, investigating that sort of thing in too much depth can
> get one flagged as a malware writer. A few days ago I saw something
> very odd happen as a result of some search terms I used when reading
> up about a particular comms protocol.
> 

In Firefox, use the Private Browsing feature, then (at least Google)
does not track what you search (also use Google Search in normal mode while
logged on to Google (important) on other terms to have them not correlate 
searches with your IP address and spew them into your personalized set anyway)

my £0.02p worth ;)

-L.

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


Re: [Lazarus] In search of a component for holding a table of strings

2017-01-10 Thread Lukasz Sokol via Lazarus
On 09/01/17 21:17, Bart via Lazarus wrote:
> On 1/9/17, Lukasz Sokol via Lazarus <lazarus@lists.lazarus-ide.org> wrote:
> 
>> For such usage, it is rather assumed that NO substring can contain EOL of
>> any kind,
> 
> For the intende purpose of TStringTable, this is certainly NOT the case.

I understand that :) and I respect that. 

> 
>> EOL is assumed to be meaning end of a string here. Not unlike TStringList
>> assuming EOL to mean end of a string.
> 
> That makes no sense to me at all.
> 

Sorry should have reiterated EOL is an end of a SUBstring... :)

> Bart
> 
-L.

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


Re: [Lazarus] In search of a component for holding a table of strings

2017-01-09 Thread Lukasz Sokol via Lazarus
On 07/01/17 21:49, Bart via Lazarus wrote:

> I think my current implementation is cleaner.
> As long as you do not plan on having a table > 1000x1000 it behaves
> quite nicely IMO.
> 

Right now i think, there is a shortage of standard non-visual classes that can 
handle
first 2 degrees of separation of data into sections in a file - by section 
delimiter or by line-endings;
Tables in other words.

The only component that can handle entire file of comma- or otherwise- 
delimited data is a TStringGrid.
But it is visual, and quite a lot of overkill for some cases - then everybody 
who reads a 
comma-separated (or even space-separated variable-length (variable decimal 
places?) sub-strings
ends up not using a TStringList, but inventing iterating over sub-strings with 
a temporary TStringList every time...
(who says you never want to use LCL Classes unit in a console program, really ?)

While if the TStringTable was to expose every row (or col) in the table as 
another TStringList, as requested,
interfacing with that (even loading directly into and from a TStringGrid when 
needed for display) would be so much easier.

For such usage, it is rather assumed that NO substring can contain EOL of any 
kind, 
EOL is assumed to be meaning end of a string here. Not unlike TStringList 
assuming EOL to mean end of a string.

YMMV but I hope some of this makes sense ;)

> Bart
> 

-L.

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


Re: [Lazarus] In search of a component for holding a table of strings

2017-01-06 Thread Lukasz Sokol via Lazarus
On 06/01/17 16:46, Michael Schnell via Lazarus wrote:
> On 06.01.2017 16:20, Bart via Lazarus wrote:
>> That makes no sense to me,
> Instead of a two dimensional array of strings you could have use a single 
> dimensional array of StringLists (a less symmetrical way, of course).
> 
> -Michael

Yeah basically access every row or col as a TStrings type (for easy .Delimited 
or .CommaText yield)

-L.

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