No - AVOID VARIANTS
See my previous post about HOW to do this
Wonât I have to modify a lot of code to work with this design, Norman?
Thanks
Right, but your code as it stands doesnât work so changing it so it works is in your best interest
Fair enough. Thanks
Could I use method overloading to replace variants? Would it be an improvement from what Norman has given me to turn it into overloaded methods?
Thanks
[quote=133504:@Oliver Scott-Brown]Wonât I have to modify a lot of code to work with this design, Norman?
[/quote]
Search & replace Variant to whatever your new class is called
The compiler will then tell you what else needs to change
Your feet will thank you
I think the term I was looking for is âvirtual functionsâ. Canât I use them to save time with referencing the variant? Thanks
Virtual functions can be overridden to change the behavior of a function in a subclass. They are not what you want here. Stick with Normanâs suggestion of a custom variant class.
Okay thanks.
Will I have to manually clear all the values of different types when assigning new values? Thanks
Take the code I posted
Put it in a small sample
Play with it so you understand whats going on
If you donât youâll be no better off than you are by using variants - just for different reasons
And no you donât
The PropType string is the important thing
As long as its set & your code refers to it to know what property to grad you should be fine
[quote=133521:@Norman Palardy]Take the code I posted
Put it in a small sample
Play with it so you understand whats going on
If you donât youâll be no better off than you are by using variants - just for different reasons
And no you donât
The PropType string is the important thing
As long as its set & your code refers to it to know what property to grad you should be fine[/quote]
I am confident with the code sample, understand it and the purpose of it and how it works, etc.
So would I create a new instance of MyVariant to keep the values cleared? Wouldnât it be easier and quicker for me not to do that and to just clear out the value (which would depend on the last used type).
Thanks
Questions like this lead me to believe you donât understand the code I posted, how it works (or why it works) & how it can help you avoid variants.
Why do you think you need to âclearâ anything - and what would you âclearâ a string to ?
An empty string is a valid string it just has no data in it.
An integer set to 0 is perfectly legal.
So what exactly would âclearingâ it do or mean ?
[quote=133538:@Norman Palardy]Questions like this lead me to believe you donât understand the code I posted, how it works (or why it works) & how it can help you avoid variants.
Why do you think you need to âclearâ anything - and what would you âclearâ a string to ?
An empty string is a valid string it just has no data in it.
An integer set to 0 is perfectly legal.
So what exactly would âclearingâ it do or mean ?[/quote]
I meant clearing out values. But I could always use a computed property and in the Getter I could make a check like this:
if mValue = nil then
mValue = new MyVariant
end if
return mValue
I do understand the code, I just did not read the bit where you institute MyVariant. Thanks for the help and I now think I know where I am going with this.
Thanks
where I did what ???
dim mv as new MyVariant
Created an instance of MyVariant, as you cannot just call it without creating an instance.
Thanks Norman.
It works great and takes away a lot of pain that I had with variants.
It should
Variants are kind of seductive as they seem so friendly, easy, etc
Right up until they arenât BECAUSE the compiler canât help etc
[quote=133565:@Norman Palardy]It should
Variants are kind of seductive as they seem so friendly, easy, etc
Right up until they arenât BECAUSE the compiler canât help etc[/quote]
I did should be a lover of variants but this technique is great for me.
I know that tags use variants so I am guessing I should just be careful and try to only assign MyVariant instances to tags then there should be less worries on the variant values. But I guess I could just use subclasses for custom variants.