How to Clear Multiple Edits Without Refering to Them One by One

Posted on December 15th, 1999 in General | No Comments »

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 := '';

How to Determine the Screen Resolution

Posted on December 15th, 1999 in Graphics | 1 Comment »

There are two ways to determine the screen’s height and width.

1) Use the global Screen variable.

uses
  Forms;
...
  Screen.Height { Screen height in pixels }
  Screen.Width  { Screen width in pixels  }
...

2) Use the Windows API GetSystemMetrics() function. This function can be useful in applications that don’t use the VCL like console applications.

uses
  Windows;
...
  GetSystemMetric(SM_CXSCREEN) { Screen height in pixels }
  GetSystemMetric(SM_CYSCREEN) { Screen width in pixels  }
...