Reference to procedure

There are parameters for "callback" procedures of the type reference to procedure. For some calls, I want to pass a nil or a null and then check if a procedure reference was passed.

  1. Nil compiles, but is probably wrong.
  2. When tracing it, it appears to be of type string

What should I pass and how should I check?

Examples

type
  TShowCrudListProc = reference to function
                      (const AElementId : string;
                             AEditProc  : TEditProc) : TWebForm;
  TShowCrudEditProc = reference to function
                      (const AElementId : string;
                             AListProc  : TListProc;
                             AId        : JSValue;
                             AEdit      : Boolean): TWebForm;


function CreateForm (AElementID : string;
                     ATitle     : string;
                     ACrud_List_Proc : TShowCrudListProc;
                     ACrud_Edit_Proc : TShowCrudEditProc) : TWebForm;

I cannot see an issue here. Using Assigned() should work.

Test code:

  TShowCrudEditProc = reference to function
                      (const AElementId : string): TWebForm;

  TForm3 = class(TWebForm)
    WebButton1: TWebButton;
    procedure WebButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

    function CreateForm (AElementID : string;
                     ATitle     : string;
                     ACrud_Edit_Proc : TShowCrudEditProc) : TWebForm;
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

function Proc(const AElementId : string): TWebForm;
begin
  Result := nil;
end;


function TForm3.CreateForm(AElementID, ATitle: string;
  ACrud_Edit_Proc: TShowCrudEditProc): TWebForm;
begin
  console.log(ACrud_Edit_Proc);

  if not Assigned(ACrud_Edit_Proc) then
    console.log('is not assigned')
  else
    console.log('assigned');
end;

procedure TForm3.WebButton1Click(Sender: TObject);
begin
  CreateForm('123','title',nil);

  CreateForm('123','title',@Proc);
end;

It works in your example, but sometimes it hasn't worked for me. Assigned passes when it should fail. I shall try and replicate when I encounter it again.