Sunday, February 02, 2025

Something that I should have learnt a long time ago in Delphi

I've shown the 'retrieve entry' form for the Blog Manager Program before; similar dialogs appear in other of my programs. In all of them, there is a short cut: should I enter an ID number or a date then pressing 'enter' is equivalent to pressing the 'show' button that retrieves the appropriate entries. This action has always been accompanied by a 'ding' and it seems that I've never been sufficiently motivated to discover why this 'ding' is sounded (I sort of know where it comes from).

Today obviously this did offend/annoy me so I went looking for the cause. The form's 'keypreview' property is set and the 'enter' is handled in the FormKeyDown method. This works but causes the ding. The solution is simple and I should have learnt this a long time ago: instead of using FormKeyDown, I should have been using FormKeyPress, as follows

procedure TChooseEntries.FormKeyPress(Sender: TObject; var Key: Char); begin if key = #13 then begin key:= #0; // prevent the 'ding' showbtnclick (nil); end end;

So simple. Now I suppose I'll have to change 40 forms in the OP's management program to stop it dinging all the time!



This day in history:

Blog #Date TitleTags
33202/02/2011A moment's hesitationMIDI, Robert Silverberg, Song writing, Soundclick, Hugh Grant

No comments: