Forum > Debugger

FPDebug: value of a Variant

(1/3) > >>

SymbolicFrank:
How can I see the value of a Variant?

Martin_fr:
Use Lazarus 2.3.

It is not implemented in 2.2.x

SymbolicFrank:
1. How can I see the value of a Variant in Lazarus 2.3?

If I can see what's inside at all, it's a long list, among which are the type and a pointer to the value. But I cannot cast that pointer to, for example, a string, if that is the type. So all it tells me, is: it is some value of this type.

2. Sometimes it just shows: "()". That's it.


When I posted the previous post, it did show what's inside. At the moment, it only shows "()". Restarting Lazarus doesn't fix it.

Martin_fr:
Ok, I missed out a point....

Tested with:
- FPC 3.2.3 (but I believe 3.2.2 should work too)
- Lazarus 2.3

So, by default you will see something like: vtype 123; vstring $0001234546
For int and bool, you get vshortint and vboolean.

That is what actually is in the variant. the declaration contains "vstring : pointer". So FPC tells the debugger this is an address, and nothing else.

But...

You can get better results. For that however you need to tell (and allow) the debugger to execute "SysVarToLStr" in you paused app  (the debugger will call that function, this will run. It can (but in this case should not) have sideeffects)

https://wiki.freepascal.org/IDE_Window:_Ide_Options_-_Backend_Value_Converter#CallSysVarToLStr

- Create a new entry (any name)
- set checkbox
- select SysVarToLStr
- enter "variant" (without quotes) in "Match type name"


See image, what I get to see for variants.

Martin_fr:
And I can typecast

--- 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";}};} ---ansistring(a.vstring)^char(a.vstring)
But only if the types (char or ansistring) are used in the app. You need a variable of that type, and it needs to be used (so it's not left out by fpc/linker)

Navigation

[0] Message Index

[#] Next page

Go to full version