Recent

Author Topic: TFileNameEdit, TDirectoryEdit (EditBtn)-how to customize behavior OnButtonClick?  (Read 5058 times)

max555

  • New Member
  • *
  • Posts: 12
Hello,
Question about TFileNameEdit, TDirectoryEdit controls from EditBtn module.
Linux; FPC 3.2; Lazarus 3.4

Is there any way to suppress/skip/disable standard OpenFile dialog when user clicks on "browse files" button on such controls?
I can use OnButtonClick event to do what is necessary, but then sometimes I need to suppress file selection dialog because file is already selected by my code.
RxTools for Delphi offers OnBeforeDialog event with Action parameter that is very useful in some cases.

As I understand its not possible for Lazaus version of these components?
May be add Action parameter to OnButtonClick event in the future?

Thank you.

jamie

  • Hero Member
  • *****
  • Posts: 6801
here is an idea. Scan the control and disable or enable the button?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FileNameEdit1MouseDown(Sender: TObject; Button: TMouseButton;
  2.   shift: TShiftState; X, Y: Integer);
  3. Var
  4.   B:TSpeedButton;
  5.   C:TControl;
  6.   I:Integer;
  7. begin
  8.   For I := 0 To FileNameEdit1.ComponentCount-1 Do
  9.    Begin
  10.      If FileNameEdit1.Components[I].ClassName = 'TEditSpeedButton' Then
  11.       Begin
  12.         C:= TControl(FileNameEdit1.Components[I]);
  13.         C.Enabled := False;
  14.         Break;
  15.       end;
  16.    end;
  17.  
  18. end;                      
  19.  
  20.  

That will disable the button when needed. of course you need to enable it at some point.
you can do this when items get selected you don't need to repen.
The only true wisdom is knowing you know nothing

max555

  • New Member
  • *
  • Posts: 12
Thank you but this does not work. Still standard dialog opens

Sieben

  • Sr. Member
  • ****
  • Posts: 372
Create your own descendants and override ButtonClick method. OOP is not about just using components...
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

jamie

  • Hero Member
  • *****
  • Posts: 6801
I think you misunderstood what I intended to show you.

You click in the general left side area to trigger the mouse event, and that code will execute, after which the Editbutton on the right will disable.

I did this using 3.6 laz so unless the class name is different from yours, it should work.


You can print the class names you get somewhere to as it searches the list.


The code I showed you was a test block intended for you to get the idea.

you would need to create a function somewhere to set or unset the button etc.

The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2376
I can use OnButtonClick event to do what is necessary, but then sometimes I need to suppress file selection dialog because file is already selected by my code.
If you don't need the built-in capabilities of these components, then just use TEditButton.

max555

  • New Member
  • *
  • Posts: 12
Quote
You click in the general left side area to trigger the mouse event, and that code will execute, after which the Editbutton on the right will disable.
Yes, but I need button to be enabled, at least until user clicks on it..
Thank you.

Quote
Create your own descendants and override ButtonClick method. OOP is not about just using components...
That's what I will do but I asked to check if there is other way. Project has a lot of forms, very many controls and Delphi + Lazarus code should be as much synchronized as possible, at least for some time.


jamie

  • Hero Member
  • *****
  • Posts: 6801
If you don't want to use code to make existing controls do your work, I suppose you could ask for a feature request, that wouldn't be all that unreasonable.

 Meanwhile back at the ranch, you could create a TFRAME with all the needed single components to give you the expected results.

 For the FileEditName, you could drop a TEDIT and  TBUtton or Tspeed button on it then you have a single drop in control with all the features you need.
 
 This is something you would be able to use multiple times once written.

 Jamie.

 
The only true wisdom is knowing you know nothing

max555

  • New Member
  • *
  • Posts: 12
Yes. Thank you!

 

TinyPortal © 2005-2018