Results 1 to 6 of 6

Thread: Pointer to Variant

  1. #1

    Question Pointer to Variant

    Hello gurus,

    Is it possible to obtain a pointer to Long (and generally numeric) and String data contained in a Variant variable?

    Any help would be much appreciated.
    Mike
    (3.2GHz i5 Core Quad w/ 16GB RAM, 2 x GTX 650Ti SLI-bridged w/ 2GB VRAM, x64 Windows 7 Ultimate Sp1)

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,806
    Blog Entries
    3
    Rep Power
    694
    Something to get you started, for Long:
    Uses "Console"
    
    PrintL "Assign long to variant:"
    
    Variant v      
    v = 123 As Long            
    
    PrintL "v = " + Variant#(v)
    
    PrintL
    PrintL "Assign another number by doing memory overlay stunt:"
    Long vptr = VarPtr(v)+8
    Long l At vptr
    
    l = 456                    
    PrintL "v = " + Variant#(v)
    
    PrintL
    PrintL "Assign another number by doing poke :"
    Poke(Long, vptr, 789)
                 
    PrintL "v = " + Variant#(v)
    
    WaitKey
    
    You can learn more about VARIANT internals for example here:
    VBA Internals: Variant Variables and Pointers in Depth


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  3. #3
    Petr,

    That clears up things for me a bit. I've just got to make sure a thinBasic Variant is an ordinary COM variant without any proprietary deviations.

    Thanks much for your help.
    Mike
    (3.2GHz i5 Core Quad w/ 16GB RAM, 2 x GTX 650Ti SLI-bridged w/ 2GB VRAM, x64 Windows 7 Ultimate Sp1)

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,806
    Blog Entries
    3
    Rep Power
    694
    Yes,

    thinBasic Variant is COM compatible


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  5. #5
    Petr,


    Is it or ? Then what the other 48 bits following VARTYPE are used for in thinBasic?

    Of course I'm just LOL-ing...


    Kind regards,
    Mike
    (3.2GHz i5 Core Quad w/ 16GB RAM, 2 x GTX 650Ti SLI-bridged w/ 2GB VRAM, x64 Windows 7 Ultimate Sp1)

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,806
    Blog Entries
    3
    Rep Power
    694
    Hehe,

    Eros added Variants specifically for use with COM, if I remember correctly - they worked well in my tests.
    For more technical background it is better to wait for his reply, but I am afraid he is kind of flooded by real-world work recently.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

Similar Threads

  1. when it's time to use a pointer?
    By largo_winch in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 3
    Last Post: 01-12-2011, 20:16
  2. Pointer methods
    By Richard in forum Real world situations and solutions using thinBasic
    Replies: 1
    Last Post: 05-02-2010, 00:48
  3. typo VARIANT # & $
    By Michael Clease in forum Fixed or cleared errors in help material
    Replies: 1
    Last Post: 06-11-2007, 16:17
  4. variant parameter
    By kryton9 in forum Power Basic
    Replies: 2
    Last Post: 24-09-2007, 18:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •