Variant datatype and Records

rocatis
Member Posts: 163
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.
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
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
Brian Rocatis
Senior NAV Developer
Elbek & Vejrup
Senior NAV Developer
Elbek & Vejrup
0
Comments
-
Sorry I sympathise, I do. Maybe you'l like this one too, it gives a wonderfully cryptic error message.
OBJECT Report 99929 Fd Up Variant { OBJECT-PROPERTIES { Date=23/07/08; Time=11:19:45; Modified=Yes; Version List=; } PROPERTIES { ProcessingOnly=Yes; OnPreReport=BEGIN V := '<A....................................'; FD.TEXTMODE(TRUE); FD.CREATETEMPFILE; FD.WRITE(V); FD.SEEK := 0; FD.READ(V); FD.CLOSE; "What's V's Type"; V := 'jjjjjjjjjjjjj'; END; } DATAITEMS { } REQUESTFORM { PROPERTIES { Width=9020; Height=3410; } CONTROLS { } } CODE { VAR FD@1000000000 : File; V@1000000001 : Variant; PROCEDURE "What's V's Type"@1000000005(); BEGIN IF V.ISRECORD THEN MESSAGE('V.ISRECORD') ELSE IF V.ISFILE THEN MESSAGE('V.ISFILE') ELSE IF V.ISACTION THEN MESSAGE('V.ISACTION') ELSE IF V.ISCODEUNIT THEN MESSAGE('V.ISCODEUNIT') ELSE IF V.ISAUTOMATION THEN MESSAGE('V.ISAUTOMATION') ELSE IF V.ISBOOLEAN THEN MESSAGE('V.ISBOOLEAN') ELSE IF V.ISOPTION THEN MESSAGE('V.ISOPTION') ELSE IF V.ISINTEGER THEN MESSAGE('V.ISINTEGER') ELSE IF V.ISDECIMAL THEN MESSAGE('V.ISDECIMAL') ELSE IF V.ISCHAR THEN MESSAGE('V.ISCHAR') ELSE IF V.ISTEXT THEN MESSAGE('V.ISTEXT') ELSE IF V.ISCODE THEN MESSAGE('V.ISCODE') ELSE IF V.ISDATE THEN MESSAGE('V.ISDATE') ELSE IF V.ISTIME THEN MESSAGE('V.ISTIME') ELSE IF V.ISBINARY THEN MESSAGE('V.ISBINARY') ELSE IF V.ISDATEFORMULA THEN MESSAGE('V.ISDATEFORMULA') ELSE IF V.ISTRANSACTIONTYPE THEN MESSAGE('V.ISTRANSACTIONTYPE') ELSE IF V.ISINSTREAM THEN MESSAGE('V.ISINSTREAM') ELSE IF V.ISOUTSTREAM THEN MESSAGE('V.ISOUTSTREAM') ELSE MESSAGE('V.NONEOFTHEABOVE'); END; BEGIN END. } }
Robert de Bath
TVision Technology Ltd0 -
rdebath wrote:
Sorry I sympathise, I do. Maybe you'l like this one too, it gives a wonderfully cryptic error message.
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 #-oBrian Rocatis
Senior NAV Developer
Elbek & Vejrup0 -
Yes, for me the Variant datatype is now finished from 60%, making it nearly unusable...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions