Recent

Author Topic: TOpenDialog  (Read 600 times)

Paolo

  • Hero Member
  • *****
  • Posts: 538
TOpenDialog
« on: November 01, 2024, 04:39:31 pm »
Hello

win-10, laz 3.6/fpc 3.2.2,

In a Topendialog I want change the file "options" according to the currently filterindex selected by user, my attempt is to allow or not allow multiselect according to the file extension. But I don't see any option to catch the filterindex change. is ti possible ?

thank you

jamie

  • Hero Member
  • *****
  • Posts: 6734
Re: TOpenDialog
« Reply #1 on: November 01, 2024, 10:05:46 pm »
..OnTypeChange?

its in there
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5465
    • Bart en Mariska's Webstek
Re: TOpenDialog
« Reply #2 on: November 01, 2024, 11:21:51 pm »
Yes, but from within that you cannot (simply) change e.g. Options (well you can change them but they have no effect on the dialog that is open at that moment).

Maybe from within that even you can send some message to the dialog window?

Bart

wp

  • Hero Member
  • *****
  • Posts: 12459
Re: TOpenDialog
« Reply #3 on: November 01, 2024, 11:50:33 pm »
I played a bit with the OpenDialog: it is possible to change the dialog's Options in the OnChangeType handler. The following (tested) code snippet toggles the MultiSelect option depending on whether the current FilterIndex is odd or even (I know this is not very enlightening...), and displays the current value in a memo:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   OpenPictureDialog1.Execute;
  4. end;
  5.  
  6. procedure TForm1.OpenPictureDialog1TypeChange(Sender: TObject);
  7. var
  8.   filters: TStringArray;
  9.   filter: String;
  10.   allowMultiSelect: string;
  11. begin
  12.   if odd(OpenPictureDialog1.FilterIndex) then
  13.     OpenPictureDialog1.Options := OpenPicturedialog1.Options + [ofAllowMultiSelect]
  14.   else
  15.     OpenPictureDialog1.Options := OpenPicturedialog1.Options - [ofAllowMultiSelect];
  16.  
  17.   filters := OpenPictureDialog1.Filter.Split('|');
  18.   filter := filters[(OpenPictureDialog1.FilterIndex-1) * 2 + 1];
  19.   allowMultiSelect := BoolToStr(ofAllowMultiSelect in OpenPictureDialog1.Options, true);
  20.   Memo1.Lines.Add('%d - %s: AllowMultiSelect = %s', [
  21.     OpenPictureDialog1.FilterIndex, filter, allowMultiSelect
  22.   ]);
  23. end;

Paolo

  • Hero Member
  • *****
  • Posts: 538
Re: TOpenDialog
« Reply #4 on: November 02, 2024, 10:36:09 am »
Tanks wp,

it works about setting true/false of AllowMultiSelect options, but in any case even if AllowMultiSelect is true it doesn't work !

Bart

  • Hero Member
  • *****
  • Posts: 5465
    • Bart en Mariska's Webstek
Re: TOpenDialog
« Reply #5 on: November 02, 2024, 05:53:34 pm »
I played a bit with the OpenDialog: it is possible to change the dialog's Options in the OnChangeType handler.

I tried something like that, but the changes do not propagate to the dialog that is currently open.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 6734
Re: TOpenDialog
« Reply #6 on: November 02, 2024, 05:59:56 pm »
One needs to reinstate the dialog after change.

This could be done via a function call to handle this using the Type Change event to restart it.

The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5465
    • Bart en Mariska's Webstek
Re: TOpenDialog
« Reply #7 on: November 02, 2024, 06:21:00 pm »
One needs to reinstate the dialog after change.

This could be done via a function call to handle this using the Type Change event to restart it.

Well, simply calling TOpenDialog(Sender).Close does not close the dialog.

Bart
« Last Edit: November 02, 2024, 06:24:58 pm by Bart »

jamie

  • Hero Member
  • *****
  • Posts: 6734
Re: TOpenDialog
« Reply #8 on: November 02, 2024, 06:28:08 pm »
Of course not, you set MODAL Results.

If I have time I'll look at it , I am sure I can make this work.

Jamie
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5465
    • Bart en Mariska's Webstek
Re: TOpenDialog
« Reply #9 on: November 02, 2024, 06:39:58 pm »
Of course not, you set MODAL Results.
No such property exists for TOpenDialog.

If you want to change the settings of the dialog while it is running, the dialog must have some mechanisme to so so.
For instance TTaskDialog handles messages sent to the dialog (both native Windows and emulated LCL implementation handle this).
I cannot see that IFileDialog has such a mechanism.

Closing and Reopening the dialog would cause flickering on the screen, but also since you normally would do
Code: Pascal  [Select][+][-]
  1.   if Dlg.Execute then ...
What would happen if you force the dialog to be closed?
I would expect that at this point Execute finishes.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 6734
Re: TOpenDialog
« Reply #10 on: November 02, 2024, 07:45:17 pm »
Apparently the LCL does not process this as one would think.

THere are EndDialog(...)and there is WM_COMMAND, IDCANCEL that can get processed but, it seems these items are getting blocked.

Oh well, I don't have time to totally dig into it now.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018