I have the need to place code/comments into ALL modules and routines automatically. This would be nice for Open Source stuff (commenting) and also for making a call at the start of a routine (debugging).
I found that Introspection-System somewhat helpful - but do not know how to write something there.
Is there any way to place code automatically at the begin of ALL routines? Constructor for Methods? Any tools like ARBED able to do that? https://tempel.org/arbed
For my own projects, I do this right in the .xojo_code files on disk. You need to be very careful, but it is possible if you don’t change the overall structure of the file… and if you break it, you buy it so to speak.
The obvious rule of caution: make a copy of the project file right next to the one you’re editing, so you can quickly check the edited file and, if it fails, replace with the copy.
Hmmm. I just want to know what happens, WHILE it’s running (Introspection does it). The way to get this is to put a piece of code everywhere it’s needed. I am using Dash for that now - it can even ask for parameters - and is in use for other IDEs also:
But the code “blows up” a bit this way - it would be better to place it in a kind of constructor for the “Method-Method”?
Another way to look at it: If you use the “Profile” function - which I like VERY much in Xojo - you see the names of the objects/methods together with the time.
The only way to crawl back the call history, at least that I know of, is to raise an exception and catch it.
The stack trace will contain a somewhat readable version of the call history.
Such as this (topmost item is the method that raised the exception)
I’d love to be able to automate any new method so that they are automatically populated with something like this:
Mac User:
I use TextExpander to accomplish this task. I have expander snippets for many different types of code
Example for the Event Handler of a Control
Const CONTROL_NAME As String = "NameOfControl"
Const EVENT_NAME As String = "Pressed"
// WINDOW NAME: NameOfWindow
// DATE/TIME: 2023 § 08/17/23 08:44 - Bearboat Software. 230817_0844
// DESCRIPTION: None
Exception err As RuntimeException
Var contextInformation As String = CurrentMethodName + EndOfLine + EndOfLine + "WINDOW: " + WINDOW_NAME + EndOfLine + "CONTROL: " + CONTROL_NAME + EndOfLine + "EVENT: " + EVENT_NAME
If Not ErrorHandling.HandleException(err, contextInformation) Then Raise err
System.DebugLog "Exception - " + CurrentMethodName
So when I start entering the code for a Control Event, I just use the keystroke shortcut for this and it all appears in the code editor as a start. NameOfControl and NameOfWindow are replaced manually with what is appropriate. Pressed is the default but it can be replaced when necessary.
It installs my error handling system automatically. It time stamps the date and time the code was written automatically. All this helps if a need arises to search for some code in the IDE,
I suspect that I would like a well-implemented template macro system, but this has worked well for me.
This is not to sell my particular choices.
I am just pointing to the TextExpander tool to get macro like function. What someone would put in their macro would obviously be up to them.
I use the control name and event to help me with searching and provide context to me when I review code and as a source for copy paste.
The fact that I have to raise an event to get the caller name (ooops …)
Still two complaints about that:
Not (realistic) automatable for each control, method …
The try … catch + raise will take lots of execution time
… though they are all simple properties which are not accessible AND that obviously methods and controls are not “really” objects - because it lacks the “super”-constructor for the method and the control?
Thank you Christian - nice peace of code you wrote. May be they should put it ito the codumentation?
Well, we get the call stack via raising an exception when reporting an error.
That code runs usually once when reporting an error and performance doesn’t matter then.
And Xojo Inc. can add text to their documentation if they like.
I just discovered TextExpander and immediately fell in love with it. Our support and sales teams use it constantly, so we already have a corporate license!
I’ll have to add new !XMETHOD and !XEVENT to my finger muscle-memory.