是否可以在过程中将对象函数作为参数传递而不是传递整个对象?
我有一个记录定义,其函数定义为公共类参数,例如:
TMyRecord = record
public
class function New(const a, b: Integer): TMyRecord; static;
function GiveMeAValue(inputValue: integer): Single;
public
a, b: Integer;
end;
该函数可能类似于:
function TMyRecord.GiveMeAValue(inputValue: Integer): Single;
begin
RESULT := inputValue/(self.a + self.b);
end;
然后我希望定义一个调用类函数的过程,GiveMeAValue
但我不想将整个记录传递给它。我可以做这样的事情吗,例如:
Procedure DoSomething(var1: Single; var2, var3: Integer, ?TMyRecord.GiveMeAValue?);
begin
var1 = ?TMyRecord.GiveMeAValue?(var2 + var3);
//Do Some Other Stuff
end;
如果是这样,那么我将如何正确地将函数作为过程参数传递?