Re: [Lazarus] External/out-of-tree LCL widgetset

2017-11-30 Thread el es via Lazarus
On 29/11/17 23:02, Graeme Geldenhuys via Lazarus wrote:
> On 2017-11-28 09:02, Michael Schnell via Lazarus wrote:
>> and  support for Delphi-typical RAD-style development.
> 
> RAD style development is highly overrated - I wish you can see the
> mess I'm looking at (not my code). Each form are 1000's of lines long
> with tons of database logic hard-coded, business logic etc. The
> business rules are scattered between data modules, UI forms and
> stored procedures. Solving a bug - a needle in a very large
> haystack.
> 

It is not easy to break free from old, procedural programming practices
especially that one of the 'best books' at the time did actively encourage
this kind of programming (Delphi 'Bible', around the time of D7, I'm looking at 
ya)

Heck, even the quasi-gui systems of old (Clipper, anyone?) were not emphasizing 
that.

(or just did not erect the business <-> GUI code barrier high enough for people 
to 
notice... or even state what it is or where it is supposed to be, or how it's 
supposed to be organized.
There is a sore lack of mid-grade non-trivial examples of that... when most 
examples for D you 
can find are 'slap a button  on the form and then paste this code to OnClick 
procedure', it starts 
inevitably to look like a hammer, to invoke the age-old pun ).

This may be 'obvious' to born and bred programmers ...

... but may not be not so for someone who just picked the Delphi for Beginners,
and tried to learn from that. Or just carried over their experience from 
Fortran, or Matlab, of all things.

> Regards, Graeme
> 

/rant ;)

-L.

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


Re: [Lazarus] Weird object variables access - fpc issue?

2017-10-24 Thread el es via Lazarus
On 24/10/17 12:59, Mattias Gaertner via Lazarus wrote:

> ASystemTime is a stack variable. That's thread-safe.
> 
> In fpc trunk it calls GetLocalTime on Unix, which fetches timezone
> every time. No global var. So it should be thread safe.
> 
>> because each thread instance would have its own local variables, right?
>> so no thread would step on each others' toes;
> 
> You have to check called code too.
> 
> Mattias
> 

On 24/10/17 13:06, Sven Barth via Lazarus wrote:
> 
> ASystemTime is a local variable, so two threads won't influence each other 
> there thus at least on Windows Now() is threadsafe. 
> 
> Regards, 
> Sven
> 
> 


MMMmmm... 

i can't exactly now but I will try to reproduce what I was seeing ...

for now sorry for the noise...

el es

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


Re: [Lazarus] Weird object variables access - fpc issue?

2017-10-24 Thread el es via Lazarus
On 24/10/17 10:04, Mattias Gaertner via Lazarus wrote:
> On Tue, 24 Oct 2017 08:59:36 +0100
> el es via Lazarus <lazarus@lists.lazarus-ide.org> wrote:
> 
>> On 23/10/17 20:00, Giuliano Colla via Lazarus wrote:
>> [snip]
>>
>> I don't remember if I was hitting AV using Now(), likely I wasn't - 
>> but due to 'normal' Now() being not thread safe, I was getting inconsistent 
>> timing results, when I used Now() both in main thread and in the thread;
> 
> AFAIK Now is thread safe. On what platform and how did you test?
> 
> Mattias
> 

Now() is literally 

function Now : TDateTime;
var ASystemTime : TSYSTEMTIME;
begin
   GetSystemTime(ASystemTime);
   Result := SystemTimeToDateTime(ASystemTime);
end;

on my installation (lazarus 1.6.4 #54278, FPC 3.0.2)

I'd say it's questionable to say it's thread-safe that way; It may be safe to 
use in
main thread (where no 2 different contexts can mangle each others ASystemTime);

But I had problems using Now() in main thread context (graphic) and in 
additional thread(s)
_simultaneously_.

I do not recall getting AV's, but I was getting mangled results when calls to 
Now() overlapped from 2 different thread contexts.

(try it by calling Now() from a TTimer.OnTimer handler, simultaneously with a 
background thread also calling Now() in a loop.)

I guess, simpler code for ThreadNow would be 'just' thread-local/nested to 
Execute() function containing just
a pair of

   GetSystemTime(ASystemTime);
   Result := SystemTimeToDateTime(ASystemTime);

(or literally a copy of Now(); )

because each thread instance would have its own local variables, right?
so no thread would step on each others' toes;

Hopefully this makes sense now ;)

el es

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


Re: [Lazarus] Weird object variables access - fpc issue?

2017-10-24 Thread el es via Lazarus
On 24/10/17 10:20, Michael Schnell via Lazarus wrote:
> On 24.10.2017 10:48, el es via Lazarus wrote:
>> [...]
>>>> begin
>>>>    repeat
>>>>    until not ThreadNowInUse;  //
>>>>       try
>>>>  ThreadNowInUse :=true;
>>>
> Busy wait actions are usually a very bad idea
> 
> Better use a TTimer for such.
> 
> -Michael
> 

I suppose you'd need to look at the parent/my post, 
where it's in full code what this function does ;)

tl/dr: it's a function that tries to get a time stamp
in (maybe less) thread-safe / (I'd rather call it) reentrant way

for use in thread timing and profiling.

So no, TTimer not appropriate here.

:)

el es

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


Re: [Lazarus] Weird object variables access - fpc issue?

2017-10-24 Thread el es via Lazarus
On 24/10/17 09:11, Mattias Gaertner via Lazarus wrote:
> On Tue, 24 Oct 2017 08:59:36 +0100
> el es via Lazarus <lazarus@lists.lazarus-ide.org> wrote:
> 
>> [...]
>> begin
>>   repeat
>>   until not ThreadNowInUse;  // 
>>   
>>   try
>> ThreadNowInUse :=true;
> 
> This is not thread safe.
> 
> Mattias
> 

Because separated by 'try' ?

I see; Will it be enough to put it like

try
  repeat
  until not ThreadNowInUse;
  ThreadNowInUse := true;

...
 
?

I haven't ran into problems with my routine yet,
but I wasn't really calling it in a very 'tight loop' 

(as it is used for timing/'profiling' the calls to hardware 'master node' 
routines
 and for deciding whether the thread should go to sleep; so there is always 
ample time
 between calls to ThreadNow() and it's only called in context of the thread; so 
the 
 'poor mans semaphore' isn't really that required - it's just a safeguard)

(probably if I need timing measurements, every other type of thread I 
will ever define, will have their own ThreadNow call)

I realize I could just use 'naked' GetSystemTime + SystemTimeToDateTime pair 
with a local variable;
or define the above pair as a nested function in the thread, that'll serialize 
it enough...

Anyone ever thought of a thread-safe global Now() call ?

el es

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


Re: [Lazarus] Weird object variables access - fpc issue?

2017-10-24 Thread el es via Lazarus
On 23/10/17 20:00, Giuliano Colla via Lazarus wrote:
[snip]

I don't remember if I was hitting AV using Now(), likely I wasn't - 
but due to 'normal' Now() being not thread safe, I was getting inconsistent 
timing results, when I used Now() both in main thread and in the thread;

So with my application I ended up re-implementing Now() into ThreadNow :

var ThreadNowInUse :boolean = false; // unit global 'just' above the function

function TMyThread.ThreadNow: TDateTime;

var ASystemTime : TSYSTEMTIME;  // struct.inc, I'm under Windows

begin
  repeat
  until not ThreadNowInUse;  // 
  
  try
ThreadNowInUse :=true;
GetSystemTime(ASystemTime);
Result := SystemTimeToDateTime(ASystemTime);
  finally
ThreadNowInUse := false;
  end;

end;

Hope this helps

el es

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


Re: [Lazarus] [PATCH] Fix problems with writing ProductVersion in VersionInfo

2017-10-04 Thread el es via Lazarus
Hi Dmitry,

On 04/10/17 03:51, Dmitry D. Chernov via Lazarus wrote:
> No, I mean, like in my signature, "Dmitry D. Chernov". Anyway that's
> not critical.
> 
> _
> 
> Dmitry D. Chernov
> 

Waldo meant to say : the cyrylic characters have been that way in your original 
email,
as you can also see below in my reply,

as in, nobody took to 'write your name in Cyrillic' 'by hand',
it's all through 'machine copy' of your original content.

Hope this helps

-L.


> 
> 04.10.2017, 12:45, "wkitty42--- via Lazarus"
> :
>> 
>> On 10/03/2017 06:09 PM, Чернов Дмитрий via Lazarus wrote:
>> 
>> Thank you. But please don't write my name in Cyrillic anymore. ;-)
>> 
>> 
>> 
>> do you mean like above in the quote header? the characters that
>> arrived here as depicted in juha's post and your original??
>> 
>> 
>> 
>> -- NOTE: No off-list assistance is given without prior approval. 
>> *Please keep mailing list traffic on the list unless* *a signed and
>> pre-paid contract is in effect with us.* -- 
>> ___ Lazarus mailing
>> list Lazarus@lists.lazarus-ide.org
>>  
>> https://lists.lazarus-ide.org/listinfo/lazarus
> 
> 


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


Re: [Lazarus] Converting all code to use UnicodeString

2017-09-28 Thread el es via Lazarus
On 27/09/17 09:16, Graeme Geldenhuys via Lazarus wrote:
> On 2017-09-27 03:51, Marcos Douglas B. Santos via Lazarus wrote:
>> A constant that can change...
> 
> 
> Yeah, that concept still blows my mind. [figuratively speaking] They
> should shoot the developer that came up with that idea - and the team
> leader that approved it.
> 
> Regards, Graeme
> 

comp.compilers.free-pascal.social is leaking ;)

It dates back to when, Turbo Pascal ?
Late 1980s / Early 1990s ?

Imagine this:

Developer (thinking): "The rave was great last weekend, still feeling the pain 
Thursday"
Developer: " we have this almost ready and this looks like a great idea"
Supervisor (thinking): "Ah the world's going to end next week anyway, who cares"
Supervisor: "OK, make it so"

;) 


-L.

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


Re: [Lazarus] [ANN] Xavier for XML — Compatible with FPC and Delphi

2017-09-25 Thread el es via Lazarus
On 22/09/17 15:44, Marcos Douglas B. Santos via Lazarus wrote:

> So, you can do like them: just use Google Translator.   :)
> 
> Regards,
> Marcos Douglas
> 

Am 22.09.2017 15:51 schrieb "el es via Lazarus" <lazarus@lists.lazarus-ide.org>:
>

>Google Translate does a rather good job of translating the articles :)

>Regards,
>Sven


I'll give it a try, thanks :)

-L.

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


Re: [Lazarus] [ANN] Xavier for XML — Compatible with FPC and Delphi

2017-09-22 Thread el es via Lazarus
On 21/09/17 17:49, Marcos Douglas B. Santos via Lazarus wrote:

> 
> [1] My posts about inheritance https://goo.gl/nzM4Ss
> 

If it only was in English ;) Unfortunately knowing Esperanto (once upon a time)
only gets you so far as 5% ;)

-L.

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


Re: [Lazarus] FPReport file names

2017-09-13 Thread el es via Lazarus
On 13/09/17 10:19, Sven Barth via Lazarus wrote:
> Am 13.09.2017 10:45 schrieb "Michael Van Canneyt via Lazarus"

>> The benefit of writing fpreport.exporthtml versus
>> fpreportexporthtml is zero.
>> 
> 
> The "." allows for a nicer disambiguation between what's the prefix
> and what's the remainder. Granted, that can be done with "_" as well,
> but in my personal opinion a "." simply looks nicer. :)
> 
> Regards, Sven

From POV of an 'ordinary user' I came to say the same thing


> fpreportexporthtml 
> fpreport.exporthtml 

is exactly only 1 character longer but the separator (. or _) makes a lot of 
difference...

-L.

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


Re: [Lazarus] custom thread reading file does not respond properly

2017-09-06 Thread el es via Lazarus
On 06/09/17 16:19, Sven Barth via Lazarus wrote:
> Am 06.09.2017 16:48 schrieb "el es via Lazarus" 
> <lazarus@lists.lazarus-ide.org <mailto:lazarus@lists.lazarus-ide.org>>:

>> - could the un-yielded code path lead to over-zealous enqueuing of the 
>> ShowStatus routine?
>> - if yes, what would happen in such case?
> 
> Both Synchronize and Sleep already causes a thread switch (the former cause 
> it will wait for the main thread to finish processing). Also I already 
> suggested TThread.Yield which is the same as ThreadSwitch.
> And as he wrote the Sleep(1) solves the problem for him.
> It's a pity though that this seems to be necessary on Mac OS X :/
> 
> Regards,
> Sven

It is neccessary in Windows for me too (but i have the opposite problem : the 
thread-processing can be
a lot shorter - hardware communications - than the time slice of the main 
thread, giving several Queue()
 or Synchronize() calls as a result;)
Because of that, I have to use a tthreadlist as a buffer between the thread and 
the main thread.

The time where I was hunting an elusive problem that did not happen under 
debugger, is never lost ;)

-l.


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


Re: [Lazarus] custom thread reading file does not respond properly

2017-09-06 Thread el es via Lazarus
On 06/09/17 15:26, el es wrote:
> On 06/09/17 10:31, Andrea Mauri via Lazarus wrote:
>> Il 05/09/2017 22:51, Sven Barth via Lazarus ha scritto:
>>>
>>> It is however solved if you add a "Yield;" after the Synchronize
>>> call. So my suspicion is that the scheduling of Mac OS X is somehow
>>> messing things up. Either the scheduling is favoring the one thread
>>> while it shouldn't (though even reducing the priority doesn't help)
>>> or the UI framework of Mac OS X (and whatever else is involved in
>>> the main thread) is so heavy weight that the timeslice of the
>>> mainthread is used up more often than not thus leading to the read
>>> thread being scheduled much more often. By using Yield (or also
>>> Sleep(), but Yield is without any pause) the thread is explicitly
>>> giving up its timeslice and that seems to be enough here...
>>>
>>
>> I changed the code following your hints and I added Yield. This is
>> not enough, it seems that the application is a little bit more
>> responding (I can click on Tedit and after seconds the text is
>> highlighted) but not enough to be usable. Actually for me it works
>> only if I add at least Sleep(1). It is a pity that there is not a
>> unique solution.
> 
> Can you try ThreadSwitch after Sleep ?
> 
> while (not Terminated) do
> begin
>   if eof(f) then
> reset(f);
>   ReadLn(f, newStatus);
>   if NewStatus <> fStatusText then
>   begin
> fStatusText := newStatus;
> //Queue(@ShowStatus);
> Synchronize(@Showstatus);
> Sleep(5);
> ThreadSwitch; ///  
>   end
>   else  // also you need to cover what happens in ANY OTHER outcome of 
> any test, e.g.
> ThreadSwitch;
>   // because if NewStatus = fStatusText, you will IMMEDIATELY jump to the 
> first instruction of the thread
>   // so adding the ThreadSwitch at the very end of the loop, you give the 
> rest of the application (the main thread) a chance to
>   // actually do anything
> end;
> 
> Thread.Execute will execute ALL THE TIME if you don't yield/threadswitch in 
> some code path, and WILL saturate your CPU.
> 
> -l,
> 

In addition to why this isn't a problem on Windows or Linux: they have 
supposedly better schedulers...

but if not all codepaths on a thread are covered to give some time to main 
thread, try to imagine what happens:

- could the un-yielded code path lead to over-zealous enqueuing of the 
ShowStatus routine?
- if yes, what would happen in such case?


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


Re: [Lazarus] custom thread reading file does not respond properly

2017-09-06 Thread el es via Lazarus
On 06/09/17 10:31, Andrea Mauri via Lazarus wrote:
> Il 05/09/2017 22:51, Sven Barth via Lazarus ha scritto:
>> 
>> It is however solved if you add a "Yield;" after the Synchronize
>> call. So my suspicion is that the scheduling of Mac OS X is somehow
>> messing things up. Either the scheduling is favoring the one thread
>> while it shouldn't (though even reducing the priority doesn't help)
>> or the UI framework of Mac OS X (and whatever else is involved in
>> the main thread) is so heavy weight that the timeslice of the
>> mainthread is used up more often than not thus leading to the read
>> thread being scheduled much more often. By using Yield (or also
>> Sleep(), but Yield is without any pause) the thread is explicitly
>> giving up its timeslice and that seems to be enough here...
>> 
> 
> I changed the code following your hints and I added Yield. This is
> not enough, it seems that the application is a little bit more
> responding (I can click on Tedit and after seconds the text is
> highlighted) but not enough to be usable. Actually for me it works
> only if I add at least Sleep(1). It is a pity that there is not a
> unique solution.

Can you try ThreadSwitch after Sleep ?

while (not Terminated) do
begin
  if eof(f) then
reset(f);
  ReadLn(f, newStatus);
  if NewStatus <> fStatusText then
  begin
fStatusText := newStatus;
//Queue(@ShowStatus);
Synchronize(@Showstatus);
Sleep(5);
ThreadSwitch; ///  
  end
  else  // also you need to cover what happens in ANY OTHER outcome of any 
test, e.g.
ThreadSwitch;
  // because if NewStatus = fStatusText, you will IMMEDIATELY jump to the 
first instruction of the thread
  // so adding the ThreadSwitch at the very end of the loop, you give the 
rest of the application (the main thread) a chance to
  // actually do anything
end;

Thread.Execute will execute ALL THE TIME if you don't yield/threadswitch in 
some code path, and WILL saturate your CPU.

-l,

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


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

2017-06-18 Thread el es via Lazarus

On 18-Jun-17 11:20, Juha Manninen via Lazarus wrote:

On Sat, Jun 17, 2017 at 11:25 PM, el es via Lazarus
<lazarus@lists.lazarus-ide.org> wrote:

But when, during the course of Queue()d callback,
I FreeAndNil() the object that had the pointer to the callback procedure, I
get SIGSEGV pointing at CheckSynchronize in Application. (address F0F0F0F0).


I don't know the details of this issue but address F0F0F0F0 means you
used compiler flag -gt (trash variables) and the variable is
uninitialized or already freed.
Yes, the flag -gt is good, helps find such errors.



It came I think, with default build settings in Lazarus 1.6.(2 i think)
I installed recently




Hence the question is, how can I know it is safe to free the object,
that has the callback subscribed to it?
One of the ways would be, to have a flag in that object, that the
callback proc will set, and so the thread will know it's now safe to
Free(andNil)() it.


A flag in an uninitialized or freed object does not help.



No, I mean, the callback (executed in main thread context) must not 
indicate that the object is ready to be freed (because the thread 
managing the objects' lifetime may free it before the callback returns).


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);
   // this is what gets executed in the MainForm

  // but then we come back here right ?
  // but then again setting the CanDestruct flag here
  // may be still too early...
  /// so I don't know...
  // unless - may there be any procedure/call I can place in
  // the FSomeObjectNotifyEvent handler, that will cause the
  // execution to NOT come back here? the reverse of 'fork'...
end;


Juha



Thanks in advance
-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-17 Thread el es via Lazarus

Hindsight, schmindsight, but here is another question:

Where does the call queued from a thread, return to ?

As in, the thread calls Queue() on a method of the
object we're interested in; and that in turn calls
a method / procedure more like / from the 'main form' unit.

The object's lifetime is controlled by the dedicated thread
(meaning only one thread is allowed to Free() it);

But when, during the course of Queue()d callback,
I FreeAndNil() the object that had the pointer to the callback 
procedure, I get SIGSEGV pointing at CheckSynchronize in Application. 
(address F0F0F0F0).


I guess, easiest way to avoid this, is 'don't do that', so i did, and
the SIGSEGV went away.

Hence the question is, how can I know it is safe to free the object,
that has the callback subscribed to it?
One of the ways would be, to have a flag in that object, that the
callback proc will set, and so the thread will know it's now safe to
Free(andNil)() it.

But are there any other, better?

Thanks in advance,
-L.

On 14-Jun-17 14:01, Lukasz Sokol via Lazarus wrote:

On 14/06/17 11:33, Mattias Gaertner via Lazarus wrote:

On Wed, 14 Jun 2017 11:12:11 +0100
Lukasz Sokol via Lazarus  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


Re: [Lazarus] Teaching Pascal at College

2016-10-15 Thread el es via Lazarus

On 14-Oct-16 17:16, Reimar Grabowski via Lazarus wrote:

On Fri, 14 Oct 2016 16:24:04 +0100
Lukasz Sokol via Lazarus  wrote:


D'oh, really.



D'oh, really? (fixed that for you)

Answer: No (well actually the part about matlab I meant serious)



Ah Matlab. Happy TU days. Calculating 2D FFT of a picture or trying to 
implement discrete audio filters with just a couple of lines of code ;)
Transformation of bitmaps through 2D FFT, applying bandpass filters and 
rev-2D-FFT ;)



Reminder to myself:
The interwebz dozn't get sarcazm
The interwebz dozn't get sarcazm
The interwebz dozn't get sarcazm



if you want sarcasm, go xkcd (386) ;)


R.



el es

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