I want to create a function that takes a variety of parameters and handles several types of tables. My initial investigations suggest to me that this is not possible.
OBJECT Codeunit 66666 Variant Test
{
OBJECT-PROPERTIES
{
}
PROPERTIES
{
OnRun=BEGIN
VariantFunction(1234);
VariantFunction('Text');
VariantFunction(Customer);
VariantFunction(Vendor);
END;
}
CODE
{
VAR
Customer@1000000000 : Record 18;
Vendor@1000000001 : Record 23;
PROCEDURE VariantFunction@1000000000(_variant@1000000000 : Variant);
VAR
recRef@1000000001 : RecordRef;
BEGIN
IF _variant.ISRECORD THEN BEGIN
recRef.GETTABLE(_variant);
MESSAGE('%1',recRef.NUMBER);
END ELSE
MESSAGE('%1',_variant);
END;
BEGIN
END.
}
}
This fails when executing recRef.GETTABLE(_variant) which means that there is no way of knowing what kind of record was passed to the function. In other words, it really doesn't make sense to use the Variant datatype to store Record datatypes.
Okay, so I figured I'd use a workaround and pass a RecordRef datatype instead of a Record datatype. That kind of works (I can figure out which table was passed), but there's a catch: there is no Variant.ISRECORDREF function so now I have no way of knowing if it was indeed a RecordRef that was passed. I could of course assume that it's a RecordRef if it isn't any of the other datatypes.
Except, I wouldn't be able to handle FieldRef and KeyRef datatypes as there are no Variant.ISFIELDREF and Variant.ISKEYREF functions either ](*,)
Conclusion: the datatype Variant would be awesome if it worked. #-o
Comments
TVision Technology Ltd
It is possible to get your code working with a minor workaround, however. If you change the READ statement to FD.READ(V2) (where V2=Variant) and then do a V := V2, \:D/
Still doesn't make much sense though. I think I'll maintain my previous conclusion: the datatype Variant would be awesome if it worked #-o
Senior NAV Developer
Elbek & Vejrup
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.