Forum > General
Comparing Variants
SymbolicFrank:
If I compare variants with VarSameValue, it raises an exception when one is a real and the other is a string. But isn't that where that function is for? I just want to know if they both have the same value.
This is with trunk, on Win10.
Example:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; uses Variants; var v1, v2: Variant;begin v1 := 3.1415; v2 := 'Bla'; if VarSameValue(v1, v2) then WriteLn('Ok.') else WriteLn('NOK!');end.
Interestingly, I had multiple Lazarusses open and when it raised the exception, it closed that copy.
Thaddy:
Does not matter. Delphi has the same result as FPC.
WooBean:
@SymbolicFrank
I would suggest reading doc at VarSameValue function.
Below self explanation:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project4; uses Variants, sysutils; var v1, v2: Variant; ok:boolean;begin v1 := 3.1415; v2 := 'Bla'; ok:= variants.VarType(v1)=variants.VarType(v2); if ok then writeln('I can compare variant values of v1 and v2') else writeln('I can''t compare variant values of v1 and v2'); try if not ok then writeln('Anyway, I''ll try'); if VarSameValue(v1, v2) then WriteLn('Ok.') else WriteLn('NOK!'); except on e: exception do begin writeln(e.message); end; end; readln;end.
SymbolicFrank:
Ok, I'll write my own function. But to me, it is a bug.
Thaddy:
Using variants for generic code is definitely a bug, if that is what you mean... O:-)
Navigation
[0] Message Index
[#] Next page