* * *

Author Topic: TFileNameEdit Execute Dialog through OnKeyDown  (Read 601 times)

M+AUDIO

  • New member
  • *
  • Posts: 43
TFileNameEdit Execute Dialog through OnKeyDown
« on: October 12, 2017, 06:00:00 pm »
Hi,
didn't wanted to bump this old thread.
since the button part does not gets the focus, handling it in TFileNameEdit.OnKeyDown is the only way I have, I think.
now my question is why such a hack? why TFileNameEdit.RunDialog is not public? what are those risks?

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3262
  • I like bugs.
Re: TFileNameEdit Execute Dialog through OnKeyDown
« Reply #1 on: October 12, 2017, 06:14:38 pm »
What exactly do you want to achieve?
There is also a separate TOpenDialog. No need to hack TFileNameEdit.

M+AUDIO

  • New member
  • *
  • Posts: 43
Re: TFileNameEdit Execute Dialog through OnKeyDown
« Reply #2 on: October 12, 2017, 06:41:57 pm »
so you suggest me to put a TOpenDialog + a TEdit + a TButton to do the job (opening a single file as input file)? instead of a single TFileNameEdit?
I think TFileNameEdit is just fine.  I wanted to give the user also ability to work with his keyboard if he wants. hence the first post.

M+AUDIO

  • New member
  • *
  • Posts: 43
Re: TFileNameEdit Execute Dialog through OnKeyDown
« Reply #3 on: October 12, 2017, 07:17:31 pm »
P. S.
It is not a big deal.
I'm doing it this way:

Code: Pascal  [Select]
  1. interface
  2.  
  3. uses
  4.   ...EditBtn...
  5.  
  6. type
  7.   { TForm1 }
  8.   TForm1 = class(TForm)
  9.   ...
  10.   procedure MyFileNameEditKeyDown(Sender: TObject; var Key: Word;
  11.   Shift: TShiftState);
  12.   ...
  13.   end;
  14.  
  15.   { TFileNameEditHelper }
  16.   TFileNameEditHelper = class helper for TFileNameEdit
  17.   public
  18.     procedure ShowDialog;
  19.   end;
  20.  
  21. implementation
  22. ...
  23. { TForm1 }
  24. procedure TForm1.MyFileNameEditKeyDown(Sender: TObject; var Key: Word;
  25.   Shift: TShiftState);
  26. begin
  27.   if (Key = VK_RETURN) and (Shift = [ssCtrl]) then
  28.     (Sender as TFileNameEdit).ShowDialog;
  29. end;
  30. ...
  31. { TFileNameEditHelper }
  32. procedure TFileNameEditHelper.ShowDialog;
  33. begin
  34.   RunDialog;
  35. end;
  36. ....
  37.  

But you saying it is not going to be public for some reasons? OK that's it.
Edit: class helper
« Last Edit: October 16, 2017, 03:57:45 pm by M+AUDIO »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3262
  • I like bugs.
Re: TFileNameEdit Execute Dialog through OnKeyDown
« Reply #4 on: October 29, 2017, 05:32:08 pm »
...
But you saying it is not going to be public for some reasons? OK that's it.
Edit: class helper
Sorry, I missed some replies for my old posts.
Yes, TFileNameEdit can be improved as needed. I just did not understand what you want to do.

[Edit] Ok, now I read the text properly.
For shortcut keys you indeed need a public RunDialog. I changed it in r56242.
Please test.
« Last Edit: October 29, 2017, 11:32:23 pm by JuhaManninen »

jamie

  • Full Member
  • ***
  • Posts: 203
Re: TFileNameEdit Execute Dialog through OnKeyDown
« Reply #5 on: October 29, 2017, 06:16:33 pm »
I believe its possible he is having a Focus issue..
I don't know where the RunDialog comes from but its best to
use a KeyUp event instead for such things. That way the current focused control has
completed before popping up another form, in this case it could be MODAL.

 That is what I get out of that.



M+AUDIO

  • New member
  • *
  • Posts: 43
Re: TFileNameEdit Execute Dialog through OnKeyDown
« Reply #6 on: October 30, 2017, 09:48:12 am »
[Edit] Ok, now I read the text properly.
For shortcut keys you indeed need a public RunDialog. I changed it in r56242.
Please test.
Yes, that was what I was asking.
Tested and its working now. thanks.

jamie
Focus issues yes, my first post was somehow cryptic indeed, and it needed more focus to get the idea. and Juha finally got it. thanks.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus