Как передать значение nil в в параметре процедуры типа объекта

Я хочу передать значение nil в параметре, который объявлен как процедура объекта

Рассмотрим этот код

Случай 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;

Случай 2

Ì найдено , если я объявлю TFooProc как тип процедура , код будет скомпилирован. (но в моем случае мне нужна процедура типа объекта )

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;

Случай 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;

Возникает вопрос Как я могу передать значение nil в качестве параметра? для работы с кодом в case 1?

7
задан Salvador 6 July 2011 в 21:16
поделиться