IInfo needs a property that indicates if the object holds a value
Issue #36
resolved
In methods and functions that take optional parameters I have previously tested IInfo.Value
against Unassigned
to determine if a parameter holds a value:
procedure TDataModuleMyStuff.dwsUnitBlahFooMethodsGetValueEval(Info: TProgramInfo; ExtObject: TObject);
begin
if (Info.Params[0].Value = Unassigned) then
// ...do something when parameter isn't supplied...
end;
After some recent changes this test now fails with a variant conversion error (can't compare a variant of type varEmpty
with one of type varUnknown
). Fair enough.
So instead I'm now doing this:
procedure TDataModuleMyStuff.dwsUnitBlahFooMethodsGetValueEval(Info: TProgramInfo; ExtObject: TObject);
begin
if (VarIsEmpty(Info.Params[0].Value)) then
// ...do something when parameter isn't supplied...
end;
However IMO both solutions are wrong as they rely on implementation details of IInfo
's use of variants.
It would be better if IInfo
provided a boolean property that indicated if it held a value or not. Something like IInfo.Assigned
, IInfo.Empty
or IInfo.IsNull
.
Comments (2)
-
reporter -
repo owner - changed status to resolved
Fixed Issue
#36, added IInfo.ValueIsEmpty + test→ <<cset 491616730681>>
- Log in to comment
Expanding on the above, for some parameter types it is currently possible to test the value
IInfo.ScriptObj
against nil:However this is not possible for the function parameter type
TInfoFunc
.Given the following script declaration:
the Delphi-side test for a specified parameter will fail. Since
TInfoFunc.FScriptObj
is nil the call toTInfoData.GetScriptObj
will end up callingTInfo.GetScriptObj
which raises an exception: Operation "IInfo.Obj" not possible on a symbol of type blah blah... (the error message probably needs to be brought up to date, btw).