CNWIZARDS is one of the major multi-purpose plugins for the Embarcadero Delphi IDE (CnWizards is made in China, a country with very talented Delphi programmers). This free plugin has a HUGE number of useful features, among them several not available in other Delphi IDE plugins, for example, Copy Component's Class Name (to name only a single example):
Another useful CnWizards feature is the Source and Comment Templates wizard:
It allows inserting customizable snippets in the source code (each with a custom keyboard shortcut). Each of these snippets can contain macros that are dynamically expanded to their local or other context. One of these context macros is %CurrProcName%, which expands to the name of the current procedure name. I use it to quickly insert CodeSite debug messages:
Recently, I needed a macro for a Source and Comment Template that generates a GUID (Globally Unique Identifier). So, I wrote a message to Liu Xiao (the maintainer of CnWizards) asking him to implement a GUID macro. He answered, "This is a nice idea, and we will implement it." One day later, it was ready!
So, I now use this macro for a procedure where I log error messages containing a unique ID (so they can be easily found in the source code whenever an error occurs):
LogError('%CurrProcName%', '%GUID%', SysErrorMessage(GetLastError));
So by simply typing SHIFT+CTRL+L, I insert this LogError Statement in the source code (ideally inside an except section):
This contains all the information I need to trace any error:
- The name of the procedure where the error occurred
- The unique ID to easily find the error occurrence
- The error cause generated by GetLastError
- The date-time when the error occurred (encoded in the name of the log file)
This is the implementation where I save the Error to a log file:
The CnWizards plugin is full of such smart features!
No comments:
Post a Comment