2008. április 18., péntek

How to use a loop to catch edit control values


I want to check if the user has filled all required DBEdit controls on a notebook, before enabling a button on the form.


If you dropped the controls onto the notebook at design time, their Owner will be the form not the notebook. This means that it will not belong to the Components array of the notebook, but of the form. The Notebook's Controls array will be all the controls it parents and that is probably the array you want to loop through.

procedure TAddFrm.SetNextBtn;
  I: Integer;
  fld: TControl;
  fldEmpty: Boolean;
  fldEmpty := False;
  with Notebook do
    for I := 0 to ControlCount - 1 do
      fld := Controls[i];
      if (fld is TDBEdit) then
        fldEmpty := TDBEdit(fld).GetTextLen = 0;
        if fldEmpty then
    AddfrmNextBtn.Enabled := not fldEmpty;

if fldName is TCustomEdit then
  fldEmpty := TCustomEdit(fldName).GetTextLen = 0;

Nincsenek megjegyzések:

Megjegyzés küldése