Check out here for an example of events
https://www.purebasic.com/documentation ... adget.html
I've been stuck in the 90s without event binding, but I'd presume your button event example doesn't list events because there's only one;a click. If not, the manual would be lacking... And I don't think it's that bad.
New to PB - questions to clear confusion
Re: New to PB - questions to clear confusion
Question 1:is compatible with:
The following, with string-type parameters, are also correct:
is compatible with:
EventType() is a PureBasic function, but since PureBasic allows the use of same names between functions and variables, EventType by itself (with no bracket suffix) simply refers to a variable. Notice the difference in the form code:
Question 2:
Similarly:
The proper sequence should be:
And this works too:
It should also be noted, that the EnableExplicit directive overrides automatic definitions, and requires all variables to be explicitly defined before use (eg: Define anIntegerVariable.i, someFloatVariable.f, anyStringVariable.s, etc).
Question 3:Both assignments above refer to the exact same file, in the exact same location.
The first reference, qualified with an absolute file path, works regardless of where the calling code file resides. The code file can be saved anywhere, even on any other disk, because the reference to the file is absolute (C:\somePath\someFolder\actualFile.txt).
However, the second reference, with only a relative file path, works only if the calling code file resides in the same folder as the referenced file, which means that it must be saved in [C:\somePath\someFolder\] in order for it to find the file [actualFile.txt].
Question 4:
Question 5:
The parameter variables in the actual procedure and the declaration need not match name-wise but must match type-wise. So, the following are correct:JaxMusic wrote:versus the procedureCode: Select all
Declare buttonEvent(EventType)
I changed the procedure reference to match. I am guessing that EventType is a system variable, so the procedure would have to match it?Code: Select all
Procedure buttonEvent(event_type)
Code: Select all
;the parameter variable [anything] defaults to integer type (.i) when no type indicated
Declare buttonEvent(anything)
Code: Select all
;the type must match the declaration - the parameter variable [somethingElse] also defaults to integer type (.i) since no type indicated
Procedure buttonEvent(somethingElse)
Code: Select all
;the parameter variable [stringVariable] is declared explicitly as string type (.s)
Declare someProcedure(stringVariable.s)
Code: Select all
;the type must match the declaration - the parameter variable [anyVariableName] must also be declared explicitly as string type (.s)
Procedure someProcedure(anyVariableName.s)
Code: Select all
; no brackets here - EventType refers to an integer (.i)
; variable (the same name is used to be more descriptive)
Declare buttonEvent(EventType)
...
...
; with brackets here - EventType() refers to the PureBasic function.
; the result returned by the EventType() function is of an integer type (.i),
; and will be passed as the argument for the buttonEvent() procedure,
; and will therefore match the declaration above.
buttonEvent(EventType())
...
...
Yes. Any code not encapsulated in procedures or modules fall within the global scope and will be executed sequentially as they are encountered. Furthermore, since PureBasic is a single-pass compiler, all definitions for arrays, variables, structures, procedures, etc., must precede their reference; meaning they must be defined or declared before they are used. Here are some examples:JaxMusic wrote:How does the compiler know where to start? There is no void main() like in C. Does it just start at code that it first encounters that is not in a procedure?
Code: Select all
;the first usage of any variable will automatically define it.
;in this case the variable [x] is defined with the default type
;which is the integer type (.i) and assigned with a value of 0
Debug x ; = 0 and not 9
;this essentially re-defines variable [x] as an integer and assigns it
;a value of 9 - this definition has no bearing on the earlier usage
Define x = 9
Debug x ; = 9
Code: Select all
Debug add(1, 2) ;throws the error [add() is not a function...]
;DEFINED after being called (incorrect)
Procedure add(a, b)
c = a + b
ProcedureReturn c
EndProcedure
Code: Select all
;DEFINED before being called (correct)
Procedure add(a, b)
c = a + b
ProcedureReturn c
EndProcedure
Debug add(1, 2) ; = 3
Code: Select all
;DECLARED before being called (correct)
Declare add(x, y) ;here the parameters are x & y
;the function [add()] is recognised here because it was declared above before being called
Debug add(1, 2)
;the function is defined after being called but works because it was declared before the first call
Procedure add(a, b) ;here the parameters are a & b
c = a + b
ProcedureReturn c
EndProcedure
Question 3:
PureBasic recognises both absolute file paths as well as relative file paths. The following illustrates them:JaxMusic wrote:What do you mean by take note of the paths? Is there an organizational issue here that I should be cognizant of? In this case I just put all the files in the same test directory I'm using.
Code: Select all
;absolute file path
filename.s = "C:\somePath\someFolder\actualFile.txt"
;relative file path
filename.s = "actualFile.txt"
The first reference, qualified with an absolute file path, works regardless of where the calling code file resides. The code file can be saved anywhere, even on any other disk, because the reference to the file is absolute (C:\somePath\someFolder\actualFile.txt).
However, the second reference, with only a relative file path, works only if the calling code file resides in the same folder as the referenced file, which means that it must be saved in [C:\somePath\someFolder\] in order for it to find the file [actualFile.txt].
Question 4:
No. This is because the form code file, which is automatically generated by the Form Designer, shouldn't be modified. Any code changed or added within form files (.pbf) will be purged, and the original code will be restored, when the form file is opened and read by the Form Designer. So, in order to continue to use the Form Designer to amend and update form files, it would be best to keep all other code in separate files.JaxMusic wrote:I assume this is because the form is exclusive to form procedures?; Event procedures need to be put in another source file.
Question 5:
The standard events procedure (as shown below) is generated only when the Generate Events Procedure checkbox is selected in the form's Property window, under the Layout properties. Deselect that, and the procedure will be removed. The constants (#PB_Event_CloseWindow, #PB_Event_Menu, #PB_Event_Gadget) are built-in PureBasic constants referring to window events that are triggered when a window is closed, a menu item is selected, or a gadget event occurred (respectively). There are other events as well (eg: #PB_Event_Timer, #PB_Event_SysTray, etc.), which are not included in the form code because they do not fall under the purview of the Form Designer.JaxMusic wrote:Are these "#PB_Event" constants always generated in a form?
Code: Select all
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
