Page 1 of 1

Value2ConstantDebug

Posted: Thu Sep 08, 2011 9:09 am
by Didelphodon
Value2ConstantDebug is a tiny little include which makes your debuging lifes easier. As soon as you're dealing with issues in event-handling you'll find out that those anonymous numbers and values are unnecessarily complicating everything and hindering your progress.

That's where/when Value2ConstantDebug comes in handy. It takes a value (f.i. of an event) and converts it back to the according constant-name.

Furthermore Value2ConstantDebug adds a smart feature as suppression of redundant values.


How to use it? Well, it's just like an enhanced Debug statement. Take a look at this example:

Code: Select all

v2cd_Debug(EventType(), "#pb_eventtype_,#pb_anti", #True, #True)
According to the procedure's (v2cd_Debug) declaration ...

Code: Select all

v2cd_Debug(value.i, constantNameFilter.s = "", suppressRedundancies.b = #True, printIfNotFound.b = #True)
... this would re-convert the EventType()-returnvalue to a (all) constant-name(s) starting with "#pb_eventtype_" or "#pb_anti".
Furthermore any redundancies would be suppressed, though counted and printed as one message when the value changes.
If no fitting constant-definition is found the value still gets printed in its original form.

Why the argument "constantNameFilter"?
Well, there are some specific values that are shared through lots of constants (names). So which would be the fitting one? The easy answer is "only YOU can", and therefore you're helping yourself by filtering out the right ones by defining the contant-name beginnings you'd like to get.

An empty "constantNameFilter" brings up only the original values, though the redundancy suppression feature still can be used.

Setting "constantNameFilter" to "#" will bring you *all* known constant-names for the according value - these might be many.

However, I was once fed up with dealing with event-issues and so I coded this tiny tool. I hope that it will also be useful to you guys.

Download

EDIT: This should work on Linux and Mac OS, too - but I didn't test it on the latter, yet.

Cheers,

Didelphodon.

Re: Value2ConstantDebug

Posted: Thu Sep 08, 2011 10:03 am
by c4s
This looks really useful, thank you!

I didn't test it right now but I already have an idea/feature request. ;-)
As I can see from the source the defining of the constants takes most of the place. Wouldn't it be possible to automatically scan/retrieve those values? (from "PureBasic\Residents\" I'd say) This way it would be possible to debug Windows own and similar constants as well. Maybe even those self-defined ones from the source code?!

Re: Value2ConstantDebug

Posted: Thu Sep 08, 2011 10:18 am
by Didelphodon
c4s wrote:This looks really useful, thank you!

I didn't test it right now but I already have an idea/feature request. ;-)
As I can see from the source the defining of the constants takes most of the place. Wouldn't it be possible to automatically scan/retrieve those values? (from "PureBasic\Residents\" I'd say) This way it would be possible to debug Windows own and similar constants as well. Maybe even those self-defined ones from the source code?!
Thx for that point. Initially I also thought of such kind of comfort but chose to have a quick'n'dirty way I could work with. However, that decision isn't carved in stone in any way. I'll take a look at it when I have time for. In the meantime, if you have any relevant modifications let me know and I'd be glad if you share them with me so I can add them to the download-version.

Cheers,
Didel.

Re: Value2ConstantDebug

Posted: Thu Sep 08, 2011 12:19 pm
by MachineCode
Didelphodon wrote:Value2ConstantDebug is a tiny little include
"Tiny"? :lol: I almost died when I saw the code after the "police line". :)

Re: Value2ConstantDebug

Posted: Thu Sep 08, 2011 12:25 pm
by Didelphodon
MachineCode wrote:
Didelphodon wrote:Value2ConstantDebug is a tiny little include
"Tiny"? :lol: I almost died when I saw the code after the "police line". :)
I meant tiny in terms of functionality ... ;-)