Setting the OnClick procedure of a Delphi button at runtime

后端 未结 2 1337
青春惊慌失措
青春惊慌失措 2021-01-17 05:38

I have a program in which I need to update a database table with information entered into edit boxes, with a button at the end to do the updating. However, the form is creat

2条回答
  •  误落风尘
    2021-01-17 06:00

    Event handlers must be declared exactly how the event type is defined. An OnClick event is declared as a TNotifyEvent which takes parameters (Sender: TObject). You cannot break that rule.

    In your case, you can wrap your own procedure inside of the event handler, like so...

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      UpdateDatabase(Edit1.text,Edit2.Text,Edit3.Text);
    end;
    

    Note that TNotifyEvent is a procedure "of object", which means your event handler must be declared inside of an object. In your case, the event handler should be declared inside your form (not in a global location).

提交回复
热议问题