How can I check if a function param 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 param, then aValue = undefined, but the <> nil check 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);
It is now depended on jQuery if "Test" is called with a param or not.
In the next version, you'll be able to use Defined() special function, it will make a strict check against undefined (it will return true for a null value).
if Defined(aValue) then
...
In the current version you can define a function to check that
function IsDefined(aValue : TObject);
begin
asm
@result = (@aValue!==undefined);
end;
end;