将字符串转给控件名.


procedure TfrmIncome.CheckBox1Click(Sender: TObject);
procedure SetStatus(CheckBox: TCheckBox; Edit: TEdit);
  begin
    if CheckBox.Checked then
    begin
      Edit.Enabled := True;
      if Edit.CanFocus then Edit.SetFocus;
      Edit.Color := clWindow;
    end
    else begin
      Edit.Enabled := False;
      Edit.Text := '0';
      Edit.ParentColor := True;
    end;
  end;

var
  Edt: TComponent;
  S: string;
begin
  if Sender is TCheckBox then
  begin
    S := TCheckBox(Sender).Name;
    S := 'Edit' + S[Length(S)];
    Edt := FindComponent(S);
    if Edt is TEdit then
      SetStatus(Sender as TCheckBox, Edt as TEdit);
  end;

end;

你可能感兴趣的:(将字符串转给控件名.)