You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Announcement
Collapse
No announcement yet.
A way to reduce using GLOBAL, or a use for USER variables.
I fail to see how that is any clearer or less "accident prone" than GLOBAL ghMenu AS DWORD.
It does exactly the same thing, but is just more cumbersome to use in the source code.
The USER long variables are perfect for the job, of course.
I've use them where I need a long or a string that has scope where ever a control or dialog is found.
And you do have eight of them for each control or dialog, which is quite a few.
But, for clarity in coding, a global, defined as a global in its name, can be quite a bit easier to remember
when you get four hundred lines down the program and don't have a list of handy notes for quick referral.
And a single global variable, the UDT does reduce the number of global variables.
Some people, not mentioning any names, can get caught up in the immediate task, and not have immediate
recall of things that they did five minutes, half an hour, or two days ago. The global UDT makes recall of
the global less bothersome. Of course, one could always do that with the USER values, by assigning
presets to the numbers one through eight.
DIALOG SET USER hwin, %hMenu, menuhandle
As a matter of convenience, and to reduce having to look back at previous code to remember.
The world is strange and wonderful.*
I reserve the right to be horrifically wrong.
Please maintain a safe following distance.
*wonderful sold separately.
> But, for clarity in coding, a global, defined as a global in its name, can be quite a bit easier to remember
So does a simple consistent naming convention
My Globals are always prefiex with a "g" before the variable type descriptor.
It's fairly obvious that gwsCurrentCountry and gwsCountries() are global wide strings storing country data.
Unfortunately, neither of those fit well in a UDT (no dynamic strings, array must be pre-dimensioned) so you then need a mixture of UDT specified globals and individually specified ones.
I still don't see any advantage in using GlobalVariables.hMenu compared to ghMenu.
>And a single global variable, the UDT does reduce the number of global variables.
It only appears to do so. You still have the same number of variables with global scope and defining them is more cumbersome:
Code:
Type GLOBALS
hMenu as DWORD
lngCurrentID as LONG
wsCurrentName as WSTRING * 20
END TYPE
GLOBAL GlobalVariables as GLOBALS
GLOBAL gwsCountries() AS WSTRING
versus
Code:
GLOBAL ghMenu as DWORD
GLOBAL glngCurrentID as LONG
GLOBAL gwsCurrentName as WSTRING
GLOBAL gwsCountries() AS WSTRING
The goal was to copy one handle to the callback function (which cannot be called by user code
Actually you CAN manually CALL a callback function from user code. Get the CODEPTR() of the procedure and use CALL DWORD if a direct call-by-name is not supported in the version of PB you are using.
I do not recommend doing this.... but you CAN do it. I'd be especially wary of calling DDT 'CALLBACK FUNCTION's, as the arguments passed to the function are "hidden" to the user.
Then keep it to yourself, or start another thread.
While your method may work, it goes directly against Help!
It may never be called directly from your code.
The line of mine that you quoted in post 27 was part of an explanation to someone else that said something not relevant to the subject of this thread.
Adam!!!! [polite mode nearly exhausted] Also see post 22 response to post 20. added: I'm also quoted in posted 18 and he brings up GLOBALMEM.
ENOUGH, ENOUGH, ENOUGH
I'm also quoted in posted 18 and he brings up GLOBALMEM .ENOUGH, ENOUGH, ENOUGH
You referred to using the USER vars to store Pointers. I pointed out another possible thing for which they could be used. You apparently never thought of this.
, it goes directly against Help!
Note that I explicitly qualified 'DDT Callback Functions" in this sentence
And why do you think I do not recommend direct calling DDT callback functions? The main reason is, the help says not to.
The line of mine that you quoted in post 27 was part of an explanation to someone else that said something not relevant to the subject of this thread
It was not only irrelevant, it was grossly in error. I thought you should know. Hell, I thought everyone should know.
I only took the time to build this post because you gave members two (2) "I never thought of that" and one (1) "grossly in error" in the same thread.
Perhaps you need to think about the old adage which starts, "People who live in glass houses..." before you start criticizing the posts of other members.
I'm pretty sure Adam will either politely remind me of the rules or chew me a new one or something in between, but you are not the only one who has had ..
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment