Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: Threads - stringlist and programming tips
« Last post by Warfley on Today at 12:37:31 pm »
In your border case, where it is hard for you to ensure the granularity of the Terminated check inside your thread, you have several other options:

 - To return CanClose=False in the OnCloseQuery on your main form during the blocking periods. You can decide when depending on your Progress event handler.

 - To continuously monitor thread.Finished after calling thread.Terminate and before thread.WaitFor:
Code: Pascal  [Select][+][-]
  1.   thread.Terminate;
  2.   while not thread.Finished do
  3.     Application.ProcessMessages;
  4.   thread.WaitFor;
  5.   thread.Free;
  6.  

  - To call thread.Terminate and start async. polling of thread.Finished:
Code: Pascal  [Select][+][-]
  1.  
  2.   procedure Form1.AsyncWaitFor(Data: PtrInt);
  3.   begin
  4.     with TThread(Data) do
  5.       if not Finished then
  6.         Application.QueueAsyncCall(@AsyncWaitFor, Data)
  7.       else
  8.       begin
  9.         WaitFor;
  10.         Free;
  11.       end;
  12.   end;
  13.  
  14.   ....
  15.   thread.Terminate;
  16.   Application.QueueAsyncCall(@AsyncWaitFor, PtrInt(thread));
  17.   ....
  18.  

In a previous post I wrote that the WaitFor can be postponed to a time when it will not block the GUI. And I'll always prefer (and recommend) to have valid references instead of such fire-and-forget contraptions.
First, this border case can *always* happen when you use a blocking call. I just found it because I am right now using gitlab zip Downloads. But you know what can also happen? Bad connectivity, where you may not receive any data for some time (remember the OS kills your application after only a few seconds of freezing. It does not need minutes).

To your approaches, you can't handle events whale doing waitfor, so how can you handle the OnClose?

Second your while not finished loop, yes that works, but then you don't need WaitFor, because your while not finished does exactly what WaitFor does. When your thread is finished using WaitFor afterwards is pointless. So yes, replacing WaitFor with a non blocking alternative is fine, and all I am advocating the whole time

And your third example is a much more complicated version of the OnTerminate event (which was the very first thing I recommened) with the bonus of again calling waitfor after the thread is finished, which is pointless. Do you really think that this is polling self queuing event is easier to use than the already existing OnTerminate event?

Lastly about FreeOnTerminate, it's actually not that hard to not use the thread again, just nil it's reference:
Code: Pascal  [Select][+][-]
  1. // in main thread
  2. Thread.terminate;
  3. Thread := nil;
  4.  
  5. //In your thread
  6. If terminated then
  7. begin
  8.   FreeOnTerminate:= true;
  9.   //your termination handler
  10. end;

If you only have one thread variable, setting it to nil not only removes any chance to accidentally call something on it, it is also a way to signalize that this thread has been killed

PS: I must admire your creativity, in this post you reinvented a non blocking waitfor, as well as a pilled version of OnTerminate to call before the blocking waitfor in order to avoid the problem of blocking waitfor (with the side effect that you made the blocking waitfor completely redundant)

So I'm wondering, why do you hang so much on waitfor, that you want to use it so hard that you even write code making it completely unnecessary, only to not have it blocking (because it literally does nothing in that situation)?
2
General / Re: Dialogue FileOpen position chose
« Last post by marcio2003 on Today at 12:23:17 pm »
Hi,
Thank you for your tips!
I'll try to use them to solve my problems.
3
LCL / OnMouseDown - How catch gamer mouse keys
« Last post by marcio2003 on Today at 12:14:41 pm »
Hi,
How can I change in runtime actions for the side keys (eg navigation keys) on the mouse?
It's not usual to see these functions used other apps except in browsers and games.
I'm some times making some apps for own use and i wanna add this functionality to my advantage.
Always, congratulations "Lazarus Team" for helping us,
Thank in advance for your attention.
4
General / Re: Routine to array all folders from a base path
« Last post by Trivius on Today at 11:46:50 am »
Thanks, but I cannot use any of those built in or add-on classes/functions as this is an internal script language, I only can use its defined commands, which primarily includes the above mentioned 'getDirList', the rest has to be manipulated by appending variables and through array management; also I can use math operators, if, elseif, else, while, etc., and 'goto' or 'goSub' in order to visit another section of code and return, sort of like calling a function.

So, I need to manually track where I am at each level of the directory structure, moving forward and down, then backout at each deadend, to continue moving downwards until the last directory is reached.

$folder_path is the current path information,
$folder is an array that holds the folder names and their index,
$i is the total count of folders,
$directories[$i] is an array holding the full directory paths that have been checked, in order from top to bottom, and following as they branch outwards
$c is the current location within the directory structure,
$directories[$c] is the folder name for the index being checked in relation to $c
$directories[$c][1] is the folder index being checked in relation to $c
5
General / Re: xlsreader package
« Last post by JanRoza on Today at 11:25:57 am »
Install package fpspreadsheet.
6
Beginners / Re: How to use customize output in LazLogger?
« Last post by Martin_fr on Today at 11:22:53 am »
I forgot: If anyone using this could find the time, and help updating the wiki.... thanks
7
For everybody who might be interested in:

Earlier i had (within topic: Dark Theme in my program?) mentioned that i had problems in my app
occuring as white flash at a treeview load. I did find a workaround here, it's fine, more or less), healing the background erasure. See: https://forum.lazarus.freepascal.org/index.php/topic,62695.30.html      (reply #43 and #44)

But i didn't know at that stage at all why exactly this issue even did occur. Occasionally, now i saw the reason why:
It's by the OnGetImageIndex, especially here by the runtime of SHGetFileInfoW when dealing with icon retrieval, just happening during the background erasure.

For to have a small test case, i found it easy to demonstrate using a ShellTreeView as an example.
Test project attached. All needed files are inside (from zamtmn's metadarkstyle repo), no package needs to be installed.

You can see by this sample how annoying the issue is. Click also on the Gif file for to see.
The test project also shows how it might be somehow circumvented a bit.
A bit, because it's still not fully convincing as all controls will eppear instantly, whereas  the treeview does not, and so it feels kind of bumpy.

It's not by a flaw of one of the compoenents involved of course, it's by Windows.
Btw., suppressing WM_ERASEBKGND (treeview scope) won't have an effect.
To establish an icon thread solely for this very special matters would appear to be too much overhead.

Any clever idea how to make it more smooth would be welcome!
8
Debugger / Re: existing variables unavailable when exception happens
« Last post by Martin_fr on Today at 11:16:57 am »
I can't tell for sure from your description what the issue is....

1) First of all, I assume Lazarus 2.2.6 ? (or 2.2.n)

2) Your OS?

3) Project Options > Debugging
 a) Generate info for debugger enabled?
 b) Type of debug info? (Dwarf ....?)
     Should be
     For GDB based debugger : Dwarf with sets
     For FpDebug: Dwarf-3 or Dwarf with sets (chose the latter, if you may switch back to gdb at some point)

4) Tools > Options > Debugger Backend 
Which debugger is selected? "GNU Debugger (gdb)" or "FpDebug (...)"

If not "FpDebug" => try FpDebug.

5)
Have you got the "Stack Window" open?  Menu: View > Debug Windows > Call Stack
If so, what does it show?

If it does show function names, which one is active (little green arrow in the left-most column)
Maybe you need to select a difference line? (select line, click "green arrow" tool button)

6)
Quote
"$" is not a valid number.
- What is the exact term you are looking at?
- Are you hovering the mouse?
- Can you copy the term to the "Watches" window?

7)
Quote
I get an FPC exception
I.e., "Run time error"?
Or "The project raised an exception ..." ?

If the first, and if "sysutils" is used, then if you continue (F9) you should get the "raised an exception" => Do you get different info then (see your code in the stacktrace, in case it had not been there before)



If you do get an "Access violation" or "Sigfault" then that is different.

E.g. if you get stack corruption, then the assemble window may open, and show you code at adress 0x0000000 (which does not exist).
Or it may show you code at a random address which may or may not be in your exe.

If your stack got corrupted, then getting data may or may not be possible. Because if the stack is corrupted, it is possible that all and any info where your code is/was has been lost.
9
General / xlsreader package
« Last post by ronhud on Today at 10:44:21 am »
Is there a package for eading xlxs files that can be installed into the Lazarus IDE?   I have seen reference to xlsreader but cant find the appropriate files
10
Debugger / Re: Tips for deep debuging of objectlists
« Last post by Martin_fr on Today at 10:43:50 am »
They are still showing the list as a pointer (e.g. $0B2055A8^:16)  I am using fgl unit fwiw. Not sure if I am missing a setting or something.

Ok, I missed "fgl".
If you have something like
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. uses fgl;
  3.  
  4. type
  5.   TBar = class
  6.     a,b: Integer;
  7.   end;
  8.  
  9.   TMyList = specialize TFPGList<TBar>;
  10.  
  11. var  MyList: TMyList;
  12.  
  13. begin
  14.   MyList := TMyList.Create;
  15.   MyList.Add(TBar.Create);
  16.   MyList.Add(TBar.Create);
  17.   MyList.Add(TBar.Create);
  18. end.

Then you have to watch the following:
Code: Text  [Select][+][-]
  1. ^TBar(MyList.FList)[0..MyList.FCount-1]

TFPGList has "FList: PByte" => so the debugger can't know what is in FList.
Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018