Page 1 of 1

Compiler command "Forget()"

Posted: Wed Sep 25, 2013 6:41 pm
by jassing
Similar to define, in that it checks for "something"
ie:

Code: Select all

CompilerIf Defined(MyProc,#pb_Procedure)
Forget would allow us to handle collisions with external libraries.
ie: Droppy lib has RegDeleteKey(); but let's say we've got one we're using.
Rather than changing all instances of our function, or removing droopy; we could issue:

Code: Select all

Forget(RegDeleteKey,#pb_procedure)
this would tell the compiler to ignore any pre existing definitions of RegDeleteKey(); so if we had droopy lib; you could do:

Code: Select all

Forget(RegDeleteKey,#pb_procedure)
procedure RegDeleteKey()
...
and then the compiler would use our definition of RegDeleteKey instead of the one the compiler already knows about.

I used droopy as an example, as it seems popular; I wrote a bunch of code that when I handed it over; they sent it back with requests to change a few (internal to my block) function names as they collide with the pre-existing programs functions.

A variation on it, might be similar to a module:

Code: Select all

 ; fnShowWindow() is already defined or it may be defined 'later' but for our block of code, we also have it, so:
SetLocal() ; Compiler directive to keep the following code as it's own universe
global hWnd
procedure fnShowWIndow()
endprocedure
EndLocal() ; Compiler directive to end the 'local definitions'
In that context, our hwnd and fnshowwindow would not collide with any pre-existing objects or any objects defined later in the program.

Part of this is thinking outloud about other ways to handle the same basic concept...

Re: Compiler command "Forget()"

Posted: Wed Sep 25, 2013 7:33 pm
by IdeasVacuum
Not sure, sounds as dangerous as the issue it would fix..........
To use it, you would need to know there is a clash? - and if you do know, then a Procedure name change is a simple find/replace........

Re: Compiler command "Forget()"

Posted: Thu Sep 26, 2013 7:21 am
by c4s
If you don't want to alter your code you can easily do this with macros:

Code: Select all

Procedure ProcOld()
	Debug "ProcOld"
EndProcedure

Procedure ProcNew()
	Debug "ProcNew"
EndProcedure


;Macro ProcOld()
;  ProcNew()
;EndMacro

ProcOld()  ; Prints "ProcOld", uncomment above macro for "ProcNew"

Re: Compiler command "Forget()"

Posted: Thu Sep 26, 2013 8:27 am
by jassing
c4s wrote:If you don't want to alter your code you can easily do this with macros:
I tried that; macro didn't alter the existence of a function w/in a userlib

Re: Compiler command "Forget()"

Posted: Thu Sep 26, 2013 9:21 am
by PB
If the compiler is told to forget a procedure, then
what happens when it finds that same procedure
again later in the code? How will it know if it's from
the lib or your replacement procedure?

Re: Compiler command "Forget()"

Posted: Thu Sep 26, 2013 11:08 am
by PMV
This Feature would be much more dangerous and confusing as what
we have discussed for a view days with moduls:
http://www.purebasic.fr/english/viewtop ... =3&t=56574

MFG PMV

Re: Compiler command "Forget()"

Posted: Thu Sep 26, 2013 2:59 pm
by BorisTheOld
@jassing

Just rename your procedures. That's what the rest of the world does.

I suggest you prefix your procedure names with "jassing_". I doubt other people would be doing the same.

And if you run into naming problems in the future --- just rename your procedures.

We use prefixes of the form: dvsnnnnn_

dvs = the initials of my company name
nnnnn = the reference number of the module in our Data Dictionary database