Recent

Author Topic: TOpenDialog: can't change dialog Title property  (Read 3825 times)

zoltanleo

  • Hero Member
  • *****
  • Posts: 509
TOpenDialog: can't change dialog Title property
« on: August 12, 2021, 12:10:17 am »
Hi folks.

I am trying to programmatically change TOpenDialog.Title. This doesn't work  >:(
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   with oDlg do
  4.   begin
  5.     Filter:= 'Item_1|*.q|Item_2|*.w|Item_3|*.e';
  6.     Execute;
  7.   end;
  8.  
  9. end;
  10.  
  11. procedure TForm1.oDlgTypeChange(Sender: TObject);
  12. begin
  13.   case oDlg.FilterIndex of
  14.     1: oDlg.Title:= 'Item_1';
  15.     2: oDlg.Title:= 'Item_2';
  16.     3: oDlg.Title:= 'Item_3';
  17.   end;
  18. end;

It's a bug?
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

wp

  • Hero Member
  • *****
  • Posts: 12909
Re: TOpenDialog: can't change dialog Title property
« Reply #1 on: August 12, 2021, 12:41:24 am »
Is this on Windows? Your project shows the same issue. But it seems to be necessary to change the Title before opening the dialog.

jamie

  • Hero Member
  • *****
  • Posts: 6989
Re: TOpenDialog: can't change dialog Title property
« Reply #2 on: August 12, 2021, 02:30:31 am »
it can be fixed.

The call back procedure for the dialog needs log the Dialog Handle somewhere when the WM_INITDIALOG message is received.

 It appears the handle that is there now is not the actual handle to the dialog window.

In any case later at some point when the caption needs to be changed it can thus use this handle with the SetWindowTExtW


 I suppose the Title property could be a littler smarter in determining what needs to be changed at the time.
The only true wisdom is knowing you know nothing

zoltanleo

  • Hero Member
  • *****
  • Posts: 509
Re: TOpenDialog: can't change dialog Title property
« Reply #3 on: August 12, 2021, 07:26:32 am »
Is this on Windows? Your project shows the same issue. But it seems to be necessary to change the Title before opening the dialog.
This is true for Linux as well (I think it will be true for Darwin as well).

If it is not possible to change the title in the OnTypeChange event, then I do not see any other practical use of this event.

it can be fixed.

I suppose the Title property could be a littler smarter in determining what needs to be changed at the time.
I think so too.

Can you create a ticket in the tracker?
« Last Edit: August 12, 2021, 07:28:06 am by zoltanleo »
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6989
Re: TOpenDialog: can't change dialog Title property
« Reply #4 on: August 12, 2021, 11:01:24 pm »
Quote
This is true for Linux as well (I think it will be true for Darwin as well).

 if I understand you correctly, this request does not work on other targets either ?

If that is the case then this is going to turn into a bigger problem to make it work for all targets with a simple patch
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6989
Re: TOpenDialog: can't change dialog Title property
« Reply #5 on: August 13, 2021, 12:12:52 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.OpenDialog1TypeChange(Sender: TObject);
  2. Var
  3.   S:WideString;
  4.   H:Thandle;
  5. begin
  6.   H := GetForeGroundWindow; { include the Windows unit}
  7.   S := 'The type has been changed to :';
  8.   Case OpenDialog1.FilterIndex of
  9.    1:S:=S+'Item1 1';
  10.    2:S:=S+'Item  2';
  11.    3:s:=S+'Item  3';
  12.    else S := S+'Default';
  13.   End;
  14.   SetwindowTextW(H, PWChar(S));
  15. end;                          
  16.  

 This seems to work for a windows target.
The only true wisdom is knowing you know nothing

zoltanleo

  • Hero Member
  • *****
  • Posts: 509
Re: TOpenDialog: can't change dialog Title property
« Reply #6 on: August 15, 2021, 09:46:47 pm »
Hi jamie

Thanks for the answer. This code works perfect, but only for Windows. I need a cross platform solution :-[
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6989
Re: TOpenDialog: can't change dialog Title property
« Reply #7 on: August 15, 2021, 10:20:24 pm »
I don't do cross targets, i do windows only currently..

Looking at the LCLIntf and Lmessages unit, it appears the SetWindowText and LM_SetText do not exist!

But it has GetForeGroundWindow, go figure..

 Must be some limitation with the widget..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018