By default the focus is passed to the next control by pressing the Tab key. Well, sometimes (when filling out forms) you may want to pass to the next control after pressing Enter. Well, here’s the code: For TEdit controls only:
Select all the TEdit controls you want to include (using the Shift key), then select the Object Inspector, choose the Events tab and double click the OnKeyPress event. This way all the selected TEdit controls will use the same code. In the code editor write this code:
if Key = #13 then begin
Perform(WM_NEXTDLGCTL, 0, 0);
Key := #0; { Eat the key }
end;
For all the controls on the form:
This method will work for all controls because the form will take care of the event. All you have to do is set the form’s KeyPreview property to True and add this code to your form’s KeyUp event:
if (Key = VK_RETURN) and (Shift = []) then
Perform(WM_NEXTDLGCTL, 0, 0);
Categories: General Tags: borland, code, codegear, control, Delphi, double click, enter, faq, free, good, ide, key, key well, Kylix, next, object inspector, onkeypress event, return, shift key, source code, tab key, tedit, tip, trick, vk, wm, working
Let’s say you have a data entry form or a MP3 ID3 tag editor form. The user clicks the “Clear” button. The more edit controls you have the less you want to write the code to clear them
Well, here’s a better idea:
procedure TMainForm.btnClear(Sender: TObject);
var
iI: Integer;
begin
for iI := 0 to ComponentCount - 1 do
if (Components[iI] is TEdit) then
TEdit(Components[iI]).Clear;
end;
If you want to exclude a edit control from being cleared use this:
!!Note: The name check must be after the VCL class check.
if (Components[iI] is TEdit) and (TEdit(Components[iI].Name <> 'edDontClear')) then
TEdit(Components[iI]).Text := '';
Categories: General Tags: access, array, borland, change, clear, code, codegear, controls, data entry, Delphi, edit, edit control, id3, Kylix, mp3, property, refering, s, source, tedit, vcl, write