Jump to content

Can I do the following (procedure inside a procedure for a MessageDlg call)?


paul.coshott

Recommended Posts

procedure TfStaffMnt.btnDeleteClick(Sender: TObject);

  procedure mbDeleteStaff(Sender: TComponent; Res: Integer);
  begin
    //code here to delete the staff record
    qStaffDelete.ParamByName('pStaffId').AsInteger := qStaff.FieldByName('pStaffId').AsInteger
    qStaffDelete.ExecSQL;
  end;

begin
  MessageDlg('Delete the selected staff member?', mtConfirmation, mbYesNo, mbDeleteStaff);
end;

I find this code much neater and easier to maintain. Any way this can be done?

Cheers,
Paul

Link to comment
Share on other sites

  • 3 weeks later...

Hello Paul,

In Delphi 10.2, the Callback  procedure "mbDeleteStaff" does'nt compile if is defined inside another procedure / function. 

You can use an anonymous procedure:

 

  MessageDlg('Delete the selected staff member?', mtConfirmation, mbYesNo,
    procedure(Sender: TComponent; Res: Integer)
    begin
      // code here to delete the staff record
      if Res = mrOk then
      begin
        qStaffDelete.ParamByName('pStaffId').AsInteger := qStaff.FieldByName('pStaffId').AsInteger
        qStaffDelete.ExecSQL;
      end;
    end
  );

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...