Recent

Author Topic: [SOLVED] TOpenDialog bug  (Read 1715 times)

superc

  • Sr. Member
  • ****
  • Posts: 251
[SOLVED] TOpenDialog bug
« on: May 17, 2023, 08:31:38 am »
Hello,

I've a big big problem with this code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   tor: TOpenDialog;
  4. begin
  5.   try
  6.     tor := TOpenDialog.Create(self);
  7.     if (tor.Execute) then
  8.       ShowMessage('ok');
  9.   finally
  10.     tor.Free;
  11.   end;
  12. end;    
  13.  

This code on lazarus32 bit works fine,  but on Lazarus 64 bit freeze all OS, I must power off pc with button; I reinstalled Lazarus 64bit with FPCupDeluxe, and with the clean install the same thing.
My version of Lazarus 64 bit is 2.2.4 with FPC 3.2.2 on Windows 11 64 bit; same error using TFilenameEdit;
thanks in advance.

« Last Edit: May 17, 2023, 12:57:30 pm by superc »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12718
  • FPC developer.
Re: TOpenDialog bug
« Reply #1 on: May 17, 2023, 10:43:15 am »
(afaik the problem is that in dialogs like TOpenDialog all extensions in the explorer are active. Usually it is those that cause the problem, not lazarus or windows)

superc

  • Sr. Member
  • ****
  • Posts: 251
Re: TOpenDialog bug
« Reply #2 on: May 17, 2023, 10:47:53 am »
(afaik the problem is that in dialogs like TOpenDialog all extensions in the explorer are active. Usually it is those that cause the problem, not lazarus or windows)

Thank you, but, what means 'all extensions in the explorer are active'? I've seen other bugs onTopenDialog in Windows64, but they go back many years....

wp

  • Hero Member
  • *****
  • Posts: 13423
Re: TOpenDialog bug
« Reply #3 on: May 17, 2023, 11:55:33 am »
I checked your code with Laz 2.2.4/FPC 3.2.2(64 bit) on Win 11 - no problems here at all. Which debugger are you using? With GDB it takes a few seconds for the dialog to appear; with FpDebug the dialog opens almost instantly; and without any debugger it appears immediately.

AlexTP

  • Hero Member
  • *****
  • Posts: 2681
    • UVviewsoft
Re: TOpenDialog bug
« Reply #4 on: May 17, 2023, 12:10:29 pm »
Try to disable Win Explorer shell extensions (eg. TortoiseSVN).

superc

  • Sr. Member
  • ****
  • Posts: 251
Re: TOpenDialog bug
« Reply #5 on: May 17, 2023, 12:46:22 pm »
Try to disable Win Explorer shell extensions (eg. TortoiseSVN).

I downloaded from https://www.nirsoft.net/utils/shexview.html ShellExView, and I disabled all non microsoft Extension, and works fine : it's a very strange behaviur......

superc

  • Sr. Member
  • ****
  • Posts: 251
Re: TOpenDialog bug
« Reply #6 on: May 17, 2023, 12:57:15 pm »
Now everything works: by disabling the non-Microsoft extensions, I managed to understand that the problem is the google drive shell extensions, that even if I have not pened the synchronization service, apparently it freezes the program and all the Lazarus IDE : thank you again.

ASerge

  • Hero Member
  • *****
  • Posts: 2477
Re: TOpenDialog bug
« Reply #7 on: May 17, 2023, 05:13:21 pm »
Now everything works:
By the way, your code contains a potential error.
Must be:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   tor: TOpenDialog;
  4. begin
  5.   tor := TOpenDialog.Create(self);
  6.   try
  7.     if (tor.Execute) then
  8.       ShowMessage('ok');
  9.   finally
  10.     tor.Free;
  11.   end;
  12. end;

Zoran

  • Hero Member
  • *****
  • Posts: 1988
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TOpenDialog bug
« Reply #8 on: May 17, 2023, 08:33:41 pm »
Now everything works:
By the way, your code contains a potential error.
Must be:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   tor: TOpenDialog;
  4. begin
  5.   tor := TOpenDialog.Create(self);
  6.   try
  7.     if (tor.Execute) then
  8.       ShowMessage('ok');
  9.   finally
  10.     tor.Free;
  11.   end;
  12. end;

Yes, for the explanation take a look at this post by PascalDragon: https://forum.lazarus.freepascal.org/index.php/topic,43172.msg358897.html#msg358897

There is another issue (not really a bug though). When creating the dialog, better call the constructor with nil parameter instead of self -- this is because you immediately free the dialog inside this procedure, so it does not need an owner. And setting the owner has an overhead when creating and when freeing (it sends notification to the owner that it is about to be destroyed and the owner searches through its owned components list to locate this dialog and remove it from the list).
As I said, not really a bug, this overhead can hardly be noticed in reality, but setting the owner in this kind of code is certainly not a good programming practise.
« Last Edit: May 17, 2023, 08:37:27 pm by Zoran »
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

superc

  • Sr. Member
  • ****
  • Posts: 251
Re: [SOLVED] TOpenDialog bug
« Reply #9 on: May 18, 2023, 08:20:37 am »
Thanks for the advice, I have the code in some places to review; you never stop learning .... Thanks so much again

 

TinyPortal © 2005-2018