Geting value from fieldRef.Value ?

EgisEgis Member Posts: 10
edited 2004-10-29 in Navision Attain
Here is my problem:
Let's say I have variable refFieldRef of type fieldRef.
Using statment
TmpValue := refFieldRef.Value;
I get field's value but variable TmpValue contains data of type Variant. I can check data type using functions like
TmpValue.IsBoolean()
but I don't know how to convert data from variant to simple Navision data type (decimal, boolean, integer).

Does anybody have ideas how to do it ?

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Try the EVALUATE function.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • EgisEgis Member Posts: 10
    Try the EVALUATE function.
    It doesn't work and I can't convert from variant type to boolean for example.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    When you look in Codeunit 423 (W1 3.70), you see the function HasValue:

    HasValue(Value : Variant) : Boolean
    CASE TRUE OF
      Value.ISBOOLEAN :
        HasValue := Value;
      Value.ISOPTION :
        HasValue := TRUE;
      Value.ISINTEGER :
        BEGIN
          Int := Value;
          HasValue := Int <> 0;
        END;
      Value.ISDECIMAL :
        BEGIN
          Dec := Value;
          HasValue := Dec <> 0;
        END;
      Value.ISDATE :
        BEGIN
          D := Value;
          HasValue := D <> 0D;
        END;
      Value.ISTIME :
        BEGIN
          T := Value;
          HasValue := T <> 0T;
        END;
      Value.ISBINARY :
        HasValue := FALSE;
      ELSE
        HasValue := FORMAT(Value) <> '';
    END;
    EXIT(HasValue);
    

    Here you see that you can just assign the Variant value to the right variable. For the Boolean type, a local variable HasValue of type Boolean has been declared, and assigned a value using HasValue := Value.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • EgisEgis Member Posts: 10
    When you look in Codeunit 423 (W1 3.70), you see the function HasValue:
    ......

    Here you see that you can just assign the Variant value to the right variable. For the Boolean type, a local variable HasValue of type Boolean has been declared, and assigned a value using HasValue := Value.

    Thanks. It's helped me to reduce code size at least 5 times.
Sign In or Register to comment.