Control array emulation

Q.    "Is it possible to create something akin to the control array in VB? For example, I want an group of buttons with a common event handler whereby the event handler picks up an integer value for the particular button. In VB this would be done via the control array  index."

A.    One way do to this is to set the Tag field for each button to a different number and then create a common OnClick event handler that looks at the Sender's (as a TButton) Tag field.  Assign the same OnClick event handler to all the buttons in the group.  The OnClick event handler would look something like this:

  procedure TForm1.Button1Click(Sender: TObject); var cap: string;
  begin
    case TButton(sender).Tag of
      1: ShowMessage('1st Button Pressed');
      2: ShowMessage('2nd Button Pressed');
      3: ShowMessage('3rd Button Pressed');
    end;
  end;

Q:  I spend alot of time checking datatypes so that accessing the same property
of different objects does GPF.

The code tends to look like this:

fldname:='';
fld:=Components[I];
if (Components[I] is TDBedit) then
   fldname:=TDBEdit(fld).DataField
else if (Components[I] is TDBLookupList) then
   fldname:=TDBlookupList(fld).DataField
else if (Components[I] is TDBLookupCombo)then
   fldname:=TDBlookupCombo(fld).DataField
else if (Components[I] is TDBListBox) then
   fldname:=TDBListBox(fld).DataField
else if (Components[I] is TDBComboBox) then
   fldname:=TDBComboBOx(fld).DataField
else if (Components[I] is TDBCheckBox) then
   fldname:=TDBCheckBox(fld).DataField
else if (Components[I] is TDBRadioGroup) then
   fldname:=TDBRadioGroup(fld).DataField
else if (Components[I] is TDBMemo) then
   fldname:=TDBMemo(fld).DataField;

Is there a way to use the classtype property in a case statement?
Would that be better?
 

A:  No and yes.  I suggest that you declare constants that represent each class.

const
  val_TEdit = 1;
  val_TButton = 2;
{etc, etc}

Then, set the tag of each object to equal the object's constant.  Then the case statement is easy.

case (sender as tComponent).tag of
{ . . . }
end;