ReneMiner
12-06-2013, 09:51
Now having some area for new ideas that have to grow before they become a real official suggest, I'm gonna lay an egg here that has to be breeded.:egg26:
Constant String Arrays with non-linear indexes
where Index is actually just a "key" like it's known from Dictionary-module.
Huh? Now what's that supposed to be?
I'll try to explain, imagine ordinary script using UI + callbacks:
Begin ControlID
%ID_BtnOK = 1
%ID_BtnCancel
%ID_BtnExit
'...
End ControlID
$Control_ID(%ID_BtnOK) = "OK"
$Control_ID(%ID_BtnCancel) = "Cancel"
$Control_ID(%ID_BtnExit) = "Exit"
' still very linear 'til here...
' - - - - - - - - - - - - - - -
' but now:
$CBMSG(%WM_Command) = "Action_"
$CBMSG(%WM_Init) = "Init_"
$CBCTLMSG(%BN_Clicked) = "ClickButton_"
'...
Dialog New pixels, 0, "TB-Script, esc to quit", 0, 0, 800, 600, Style, ExStyle To hWin1
$DialogID(hWin1) = "Window1_"
Dialog New pixels, 0, "another window", 0, 0, 640, 480, Style, ExStyle To hWin2
$DialogID(hWin2) = "Window2_"
'...
Callback Function universalCallback()
Call_IfExists $DialogID(CBHNDL) + $CBMSG(CBMSG) + $CBCTLMSG(CBCTLMSG) + $Control_ID(CBCTL) (CBLPARAM, CBWPARAM, CBNMID, CBNHWND, CBMHDR)
' nothing else needed...
' no select case nor other filtering...
End Function
' rest reads like this:
Sub Window1_Action_ClickButton_OK(Byval lCBLPARAM As Long, Byval lCBWPARAM As Long, Byval lCBNMID As Long, Byval lCBNHWND As Long, Byval lCBMHDR as Long)
End sub
Sub Window2_Action_ClickButton_OK(...)
End sub
Sub Window1_Action_ClickButton_Cancel(...)
End sub
OK, for the callback-messages there should be fixed built-in constant strings - sure - I could use a function like this:
Callback Function universalCallback()
local sMsg as String
sMsg = GetName(CBHNDL)
sMsg += GetName(CBMSG)
sMsg += GetName(CBCTLMSG)
sMsg += GetName(CBCTL)
Call_IfExists sMsg (CBLPARAM, CBWPARAM, CBNMID, CBNHWND, CBMHDR)
End Function
Function GetName(ByVal forWhat as Long) As String
' very simplified, should be different function for each "parameter-style"
Select Case ForWhat
Case %WM_Command
Return "Action_"
Case %BN_Clicked
Return "ClickButton_"
'...etc...
End Select
End Function
but somehow I don't like it this way because that Select Case neutralizes the "Call_IfExists"-advantage again.
Dictionary could be a work-around without the need to Select Case...
So it would be great to have a fixed constant-string-table for common CB-messages and the opportunity to create like
constant strings that have a "key" in parenthesis (like an Index)
The use of callbacks here is just an example and the most common and easiest understandable reason- I have a lot of other usage in mind...
Constant String Arrays with non-linear indexes
where Index is actually just a "key" like it's known from Dictionary-module.
Huh? Now what's that supposed to be?
I'll try to explain, imagine ordinary script using UI + callbacks:
Begin ControlID
%ID_BtnOK = 1
%ID_BtnCancel
%ID_BtnExit
'...
End ControlID
$Control_ID(%ID_BtnOK) = "OK"
$Control_ID(%ID_BtnCancel) = "Cancel"
$Control_ID(%ID_BtnExit) = "Exit"
' still very linear 'til here...
' - - - - - - - - - - - - - - -
' but now:
$CBMSG(%WM_Command) = "Action_"
$CBMSG(%WM_Init) = "Init_"
$CBCTLMSG(%BN_Clicked) = "ClickButton_"
'...
Dialog New pixels, 0, "TB-Script, esc to quit", 0, 0, 800, 600, Style, ExStyle To hWin1
$DialogID(hWin1) = "Window1_"
Dialog New pixels, 0, "another window", 0, 0, 640, 480, Style, ExStyle To hWin2
$DialogID(hWin2) = "Window2_"
'...
Callback Function universalCallback()
Call_IfExists $DialogID(CBHNDL) + $CBMSG(CBMSG) + $CBCTLMSG(CBCTLMSG) + $Control_ID(CBCTL) (CBLPARAM, CBWPARAM, CBNMID, CBNHWND, CBMHDR)
' nothing else needed...
' no select case nor other filtering...
End Function
' rest reads like this:
Sub Window1_Action_ClickButton_OK(Byval lCBLPARAM As Long, Byval lCBWPARAM As Long, Byval lCBNMID As Long, Byval lCBNHWND As Long, Byval lCBMHDR as Long)
End sub
Sub Window2_Action_ClickButton_OK(...)
End sub
Sub Window1_Action_ClickButton_Cancel(...)
End sub
OK, for the callback-messages there should be fixed built-in constant strings - sure - I could use a function like this:
Callback Function universalCallback()
local sMsg as String
sMsg = GetName(CBHNDL)
sMsg += GetName(CBMSG)
sMsg += GetName(CBCTLMSG)
sMsg += GetName(CBCTL)
Call_IfExists sMsg (CBLPARAM, CBWPARAM, CBNMID, CBNHWND, CBMHDR)
End Function
Function GetName(ByVal forWhat as Long) As String
' very simplified, should be different function for each "parameter-style"
Select Case ForWhat
Case %WM_Command
Return "Action_"
Case %BN_Clicked
Return "ClickButton_"
'...etc...
End Select
End Function
but somehow I don't like it this way because that Select Case neutralizes the "Call_IfExists"-advantage again.
Dictionary could be a work-around without the need to Select Case...
So it would be great to have a fixed constant-string-table for common CB-messages and the opportunity to create like
constant strings that have a "key" in parenthesis (like an Index)
The use of callbacks here is just an example and the most common and easiest understandable reason- I have a lot of other usage in mind...