Page 1 of 1
#PB_*_FirstCustomValue should work like MacroExpandedCount
Posted: Fri Jul 06, 2018 7:37 pm
by Sicro
Instead of the constants:
- #PB_Event_FirstCustomValue
- #PB_EventType_FirstCustomValue
commands that works like "MacroExpandedCount" would be very good:
- GetFreeEventNumber
- GetFreeEventTypeNumber
Edit: Fixed typos
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Fri Jul 06, 2018 8:48 pm
by NicTheQuick
+1
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sat Jul 07, 2018 9:35 am
by mk-soft
+1
Small tip
Code: Select all
;-TOP
Macro MyEvent_NextCustomValue
($7FFFFFFF - MacroExpandedCount)
EndMacro
Macro MyEventType_NextCustomValue
($7FFFFFFF - MacroExpandedCount)
EndMacro
Debug MyEvent_NextCustomValue
Debug MyEvent_NextCustomValue
Debug MyEvent_NextCustomValue
Debug MyEventType_NextCustomValue
Debug MyEventType_NextCustomValue
Debug MYEventType_NextCustomValue
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sat Jul 07, 2018 2:36 pm
by Little John
Sorry, I don't understand the reason for this feature request.
Can you please explain it?
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sat Jul 07, 2018 3:05 pm
by nco2k
nah, FirstCustomValue should stay as it is. i wouldnt mind a NextCustomValue though. but shouldnt it work like this @mk-soft?
Code: Select all
Macro PB_Event_NextCustomValue
($FFFF + MacroExpandedCount)
EndMacro
Macro PB_EventType_NextCustomValue
($3FFFF + MacroExpandedCount)
EndMacro
c ya,
nco2k
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sat Jul 07, 2018 5:30 pm
by Sicro
@mk-soft, @nco2k:
Yes, there are many workarounds for it...
Little John wrote:Sorry, I don't understand the reason for this feature request.
Can you please explain it?
If you don't use third-party include codes, this is how you can solve the problem:
Code: Select all
; Content of include file "whatever1.pbi":
Enumeration CustomEvents #PB_Event_FirstCustomValue
#myCustomEvent1
#myCustomEvent2
#myCustomEvent3
#myCustomEvent4
EndEnumeration
; End of include file "whatever1.pbi"
; Content of include file "whatever2.pbi":
Enumeration CustomEvents
#myCustomEvent5
#myCustomEvent6
EndEnumeration
; End of include file "whatever2.pbi"
; Main code
Debug #myCustomEvent1 ; = #PB_Event_FirstCustomValue
Debug #myCustomEvent2 ; = #PB_Event_FirstCustomValue + 1
Debug #myCustomEvent3 ; = #PB_Event_FirstCustomValue + 2
Debug #myCustomEvent4 ; = #PB_Event_FirstCustomValue + 3
Debug #myCustomEvent5 ; = #PB_Event_FirstCustomValue + 4
Debug #myCustomEvent6 ; = #PB_Event_FirstCustomValue + 5
But if you use third-party include codes, it could look like this:
Code: Select all
; Content of include file "whatever1.pbi":
Enumeration #PB_Event_FirstCustomValue
#myCustomEvent1
#myCustomEvent2
#myCustomEvent3
#myCustomEvent4
EndEnumeration
; Followed by more code
; End of include file "whatever1.pbi"
; Content of include file "whatever2.pbi":
#Event_whatever = #PB_Event_FirstCustomValue
; Followed by more code
; End of include file "whatever2.pbi"
; Main code
Debug #myCustomEvent1 ; = #PB_Event_FirstCustomValue
Debug #myCustomEvent2 ; = #PB_Event_FirstCustomValue + 1
Debug #myCustomEvent3 ; = #PB_Event_FirstCustomValue + 2
Debug #myCustomEvent4 ; = #PB_Event_FirstCustomValue + 3
Debug #Event_whatever ; = #PB_Event_FirstCustomValue
The events "#myCustomEvent1" and "#Event_whatever" are in conflict in the above code.
If we had the commands wished for in this thread, the problem would not exist:
Code: Select all
; Content of include file "whatever1.pbi":
#myCustomEvent1 = GetFreeEventNumber
#myCustomEvent2 = GetFreeEventNumber
#myCustomEvent3 = GetFreeEventNumber
#myCustomEvent4 = GetFreeEventNumber
; Followed by more code
; End of include file "whatever1.pbi"
; Content of include file "whatever2.pbi":
#Event_whatever = GetFreeEventNumber
; Followed by more code
; End of include file "whatever2.pbi"
; Main code
Debug #myCustomEvent1 ; = #PB_Event_FirstCustomValue
Debug #myCustomEvent2 ; = #PB_Event_FirstCustomValue + 1
Debug #myCustomEvent3 ; = #PB_Event_FirstCustomValue + 2
Debug #myCustomEvent4 ; = #PB_Event_FirstCustomValue + 3
Debug #Event_whatever ; = #PB_Event_FirstCustomValue + 4
But I see now that we have a new problem:
Code: Select all
Enumeration GetFreeEventNumber
#myCustomEvent1 ; = #PB_Event_FirstCustomValue
#myCustomEvent2 ; = #PB_Event_FirstCustomValue + 1
#myCustomEvent3 ; = #PB_Event_FirstCustomValue + 2
#myCustomEvent4 ; = #PB_Event_FirstCustomValue + 3
EndEnumeration
Enumeration GetFreeEventNumber
#myCustomEvent5 ; = #PB_Event_FirstCustomValue + 1
#myCustomEvent6 ; = #PB_Event_FirstCustomValue + 2
#myCustomEvent7 ; = #PB_Event_FirstCustomValue + 3
#myCustomEvent8 ; = #PB_Event_FirstCustomValue + 4
EndEnumeration
The conflict exists again: The event constants "#myCustomEvent2" and "#myCustomEvent5" have the same value.
The compiler must call the enumeration parameter each line, but as it is currently the compiler doesn't do that.
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sat Jul 07, 2018 7:24 pm
by Little John
Sicro wrote:But if you use third-party include codes, it could look like this:
I see now. Thanks for your detailed explanation. I didn't think of third-party include codes.
Sicro wrote:But I see now that we have a new problem:
I think with a new function such as GetFreeEventNumber(), things will work reliably only if this function and nothing else will be used for generating event numbers. Enumerations shouldn't be used at all in this context:
Code: Select all
; WRONG:
Enumeration GetFreeEventNumber()
#MyEvent1
#MyEvent2
#MyEvent3
EndEnumeration
; CORRECT:
#MyEvent1 = GetFreeEventNumber()
#MyEvent2 = GetFreeEventNumber()
#MyEvent3 = GetFreeEventNumber()
So some discipline is required, not only when writing the main code, but also with regard to the code located in the include files. Anyway, with such a feature it will be easier than now to write conflict free code. Thanks for the suggestion!
+1
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sat Jul 07, 2018 7:48 pm
by ts-soft
Most problems like this can you solve with my include "CommonConstants"
Code: Select all
CompilerIf Defined(CommonConstants, #PB_Module) = 0
DeclareModule CommonConstants
; Form
Enumeration FormWindow
EndEnumeration
Enumeration FormGadget
EndEnumeration
Enumeration FormMenu
EndEnumeration
Enumeration FormImage
EndEnumeration
Enumeration FormFont
EndEnumeration
; Event
Enumeration EventCustom #PB_Event_FirstCustomValue
EndEnumeration
Enumeration EventTypeCustom #PB_EventType_FirstCustomValue
EndEnumeration
EndDeclareModule
Module CommonConstants
EndModule
CompilerEndIf
UseModule CommonConstants
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sat Jul 07, 2018 11:49 pm
by Sicro
@ts-soft: Yes, this is also a great workaround for this problem.
Here is my workaround:
Code: Select all
Macro GetFreeEventNumber
; MacroExpandedCount is used to reduce the unused value range
(#PB_Event_FirstCustomValue + #PB_Compiler_Line - MacroExpandedCount)
EndMacro
Enumeration GetFreeEventNumber
#CustomEvent1
#CustomEvent2
#CustomEvent3
EndEnumeration
Enumeration GetFreeEventNumber
#CustomEvent4
#CustomEvent5
#CustomEvent6
EndEnumeration
Debug #CustomEvent1
Debug #CustomEvent2
Debug #CustomEvent3
Debug #CustomEvent4
Debug #CustomEvent5
Debug #CustomEvent6
Debug GetFreeEventNumber
But a nativly solution would be better. because it forces a standard code style.
The problem with workarounds is that some programmers use it and others don't.
Re: #PB_*_FirstCustomValue should work like MacroExpandedCou
Posted: Sun Jul 08, 2018 9:35 am
by Little John
@ts-soft:
Very good idea, thank you!