Is Variant a FolderItem

  1. last week

    Christopher W

    Jan 14 Pre-Release Testers

    So I have figured out how to check for most variant types, but folder items always seem to come up as Object, the same goes for Dictionary and various other items. I am wondering how I would I go about determining if a variant contains a folderitem?

    For some reason I was under the impression that this would cause an exception, but testing shows otherwise.

    Edit: ... would cause an exception if the variant held a non-object like integer or boolean...

  2. Kem T

    Jan 14 Pre-Release Testers, Xojo Pro, XDC Speakers, MVP Connecticut
    if v.Type = Variant.TypeObject and v isa FolderItem [ or Dictionary, etc ] then
      ...
  3. Christian S

    Jan 14 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    a simple

    if v isa FolderItem then

    is enough as Variants are always objects, so isa will work just fine.

  4. Kem T

    Jan 14 Pre-Release Testers, Xojo Pro, XDC Speakers, MVP Answer Connecticut
    Edited last week

    For some reason I was under the impression that this would cause an exception, but testing shows otherwise.

    Edit: ... would cause an exception if the variant held a non-object like integer or boolean...

  5. Christian S

    Jan 14 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    when variant contains an integer, it references a VariantInteger object, which you won't see in Xojo.
    So variant is always an object and if you use VarType, it checks for the various known types and returns the right number for the internal variant classes. For all other it returns 9.

  6. Karen A

    Jan 14 Pre-Release Testers
    Edited last week

    @ChristianSchmitz a simple

    if v isa FolderItem then

    is enough as Variants are always objects, so isa will work just fine.

    Interesting I always do:

    Variant.Objectvalue IsA ClassName

    Because I always thought of the variant itself being an object that contains an item of any type, and I wanted to make sure I was comparing the right things!

    -karen

  7. Christian S

    Jan 14 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    As far as I know Objectvalue is a simple function to return just the variant itself, just with object as data type.
    I prefer variant as I don't need to cast explicitly.

  8. Karen A

    Jan 14 Pre-Release Testers

    @ChristianSchmitz As far as I know Objectvalue is a simple function to return just the variant itself, just with object as data type.
    I prefer variant as I don't need to cast explicitly.

    I always thought of Variant.Object Vale as analogous for example to variant.IntegerValue...

    In other words that all the Variant.*Value methods return what the variant contains as that specific type if possible.

    -Karen

  9. Christopher W

    Jan 14 Pre-Release Testers

    @Kem T if v.Type = Variant.TypeObject and v isa FolderItem [ or Dictionary, etc ] then ...

    This did the trick, quite nicely, thank you.

or Sign Up to reply!