How to check if function parameter is undefined?
procedure Test(aValue: TObject);
begin
if aValue <> nil then
ShowMessage('param filled') <-- also when Test() is executed!
else
ShowMessage('no param filled') <-- not called, only when Test(nil) is called
end;
However, when this function is called in pure JS without a parameter, then aValue = undefined, but the check <> nil is converted to == null!
For example, when you have a JS function with a callback:
type
TObjectProcedure = procedure(aValue: TObject);
procedure FetchUrlAsync(aUrl: string; aCallback: TObjectProcedure )
begin
asm
$().load(@aUrl, @aCallback);
end;
end;
You can call this function with:
FetchUrlAsync('ajax/test.html', Test);
Now it depends on jQuery if "Test" is called with a parameter or not.
source
share