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: at once, borland, clear, code, Delphi, edit, multiple, object pascal, source, source code, tedit, tip, trick
When creating forms with a lot of data entry you may want to consider the option to let the user focus the next edit control by hitting the Enter key. The default key is Tab which can become annoying 
All we have to do is add the following code the each TEdit control on the form. You can do so by holding down the shift key and selecting each control. Then click the ObjectInspector and double click on OnKeyPress to create a shared event for all the controls. Then enter this code in the event procedure:
...
uses
Windows;
...
if Key = #13 then begin
{ Make Windows focus the next edit control }
Perform(WM_NEXTDLGCLTL, 0, 0);
{ Eat the enter key }
Key := #0;
end;
...
This code will work only with the controls that use this OnKeyPress event.
If you want all the edit controls on the form to act this way use a different way. This code does not require each edit control to use the above routine. Just the form’s KeyPreview property to True. Now add this code to the form’s KeyUp event and your all set
If, for some reason you want to exclude any edit control from using Enter key instead to pass the focus all you have to do is modify the if condition to exclude certain edits. Instead of using there names you may want to consider the Tag property for this.
...
if (Key = VK_RETURN) and ([ssCtrl, ssShift] * Shift = []) then
Perform(WM_NEXTDLGCTL, 0, 0);
...
Note: Tip #42 refers to this topic too.
Categories: General Tags: add, ani, code, coding, control, controls, create, creating, data, default, different, edit, editing, enter, form, forms, key, make, modify, name, next, procedure, property, refering, routine, set, shift, tab, tedit, tip, use, window, windows, working