Page 1 of 1
RedefineMacro
Posted: Mon Dec 19, 2016 12:26 pm
by Josh
In some cases it would be helpful if we could disable a macro at short notice. See the following example:
Code: Select all
Macro ComputerName
MyComputerName
EndMacro
Procedure.s MyComputerName()
;.....................
;.....................
CompilerIf #PB_Compiler_Debugger
ProcedureReturn "Harrys Computer"
CompilerElse
UndefineMacro ComputerName
ProcedureReturn ComputerName()
;RedefineMacro ComputerName
CompilerEndIf
;.....................
;.....................
EndProcedure
MessageRequester ("", ComputerName())
Ok, rather than RedefineMacro you could rebuild the macro, but it's not very smart and the errors are pre-programmed with every change.
After UndefineMacro, there would be two possibilities:
- Create a completely new Macros (like now)
- Reactivate the old macro with RedefineMacro.
Re: RedefineMacro
Posted: Mon Dec 19, 2016 8:53 pm
by Mistrel
Your request is very confusing; as is your example. I would highly recommend rethinking your course of logic.
Re: RedefineMacro
Posted: Mon Dec 19, 2016 9:19 pm
by Josh
Mistrel wrote:Your request is very confusing; as is your example. I would highly recommend rethinking your course of logic.
Of course you are right, the first three lines have unfortunately been duplicated somehow. Otherwise, the example should be clear and I think that the one it affects has understood what it is all about.
I would strongly recommend that you consider your way here in the forum, that you always have to comment on everything, whether you understood what it is or not, no matter if you have something to contribute or not.
Re: RedefineMacro
Posted: Tue Dec 20, 2016 12:47 am
by normeus
@josh,
go back and edit your post. Delete first, second and third line so that it will not be confusing.
then you could do something like
Code: Select all
CompilerIf #PB_Compiler_Debugger
Macro ComputerName
"JOSH"
EndMacro
CompilerElse
Macro ComputerName
"FINDIT"
EndMacro
CompilerEndIf
Procedure.s findComputerName()
If ComputerName = "FINDIT"
Debug "LENGTHY PROCEDURE TO FIND NAME"
Debug ComputerName
Else
Debug ComputerName
EndIf
EndProcedure
findComputerName()
You are requesting a change in the way the compiler works. I am just giving you a workaround until your change is implemented.
People are not trying to be rude.... it is google translate who is at fault here!
Norm.
Re: RedefineMacro
Posted: Tue Dec 20, 2016 7:29 am
by Josh
Hello normeus,
first of all, thank you for your mediation. Although I do not like it normally, if a answered post is changed, I have removed the lines as recommended by you.
There are always several ways to reach the same goal. Your code suggestion is from a completely different approach, but it is a quite usual method to override certain functions by macro and this would simplify by my suggestion in some cases the code.
As I wished many years ago undefineMacro, no one has screamed, we need, rather the opposite. For some years now we have this feature now and when I google to 'Purebasic undefineMacro', then I suddenly get 452 results, although at that time apparently nobody found it useful.