如何在对象类型的过程参数中传递一个nil值

Sal*_*dor 7 delphi delphi-2007 delphi-xe

我想在声明为的参数中传递一个nil值 procedure of object

考虑这段代码

情况1

type
  TFooProc = procedure(Foo1, Foo2 : Integer) of object;


procedure DoSomething(Param1:Integer;Foo:TFooProc);overload;
var
  a, b : Integer;
begin
   a:=b*Param1;
   //If foo is assigned
   if @Foo<>nil then
    Foo(a, b);
end;

procedure DoSomething(Param1:Integer);overload;
begin      
  DoSomething(Param1,nil);//here the delphi compiler raise this message [DCC Error] E2250 There is no overloaded version of 'DoSomething' that can be called with these arguments
end;
Run Code Online (Sandbox Code Playgroud)

案例2

我发现,如果我声明TFooProcprocedure类型的代码被编译.(但在我的情况下,我需要一种procedure of object类型)

type
  TFooProc = procedure(Foo1, Foo2 : Integer);


procedure DoSomething(Param1:Integer;Foo:TFooProc);overload;
var
  a, b : Integer;
begin
   a:=b*Param1;
   //If foo is assigned
   if @Foo<>nil then
    Foo(a, b);
end;

procedure DoSomething(Param1:Integer);overload;
begin
  DoSomething(Param1,nil);
end;
Run Code Online (Sandbox Code Playgroud)

案例3

另外我发现如果删除overload指令,代码编译得很好

type
  TFooProc = procedure(Foo1, Foo2 : Integer) of object;


procedure DoSomething(Param1:Integer;Foo:TFooProc);
var
  a, b : Integer;
begin
   a:=b*Param1;
   //If foo is assigned
   if @Foo<>nil then
    Foo(a, b);
end;

procedure DoSomething2(Param1:Integer);
begin
  DoSomething(Param1,nil);
end;
Run Code Online (Sandbox Code Playgroud)

问题是How i can pass the nil value as parameter?如何使用案例1中的代码?

Ser*_*yuz 12

对TFooProc进行类型测试:

DoSomething(Param1, TFooProc(nil));
Run Code Online (Sandbox Code Playgroud)