Anonymous user
Repeat: Difference between revisions
no edit summary
No edit summary |
No edit summary |
||
Line 356:
4 proc called
5 proc called
</pre>
=={{header|Gambas}}==
Note: Gambas cannot performs this task as specified, as it does not have delegates, and pointers do not seem to work with procedures. What does work is using Object.Call, which is intended for executing procedures from external libraries. However the accepting procedure must refer to the object containing the procedure, and refer to the procedure by a String name. In this case, the current module/class reference (Me) is used, but the String name must be passed. This arrangement will only work within the same module/class. It may be possible to pass the parent reference to a method (taking 3 parameters) in another class if the named procedure is Public. The empty array ([]) in Object.Call represent a procedure without parameters, which are not an explicit requirement for this Task, but might another parameter to the accepting procedure.
<lang gambas>
Public Sub Main()
RepeatIt("RepeatableOne", 2)
RepeatIt("RepeatableTwo", 3)
End
'Cannot pass procedure pointer in Gambas; must pass procedure name and use Object.Call()
Public Sub RepeatIt(sDelegateName As String, iCount As Integer)
For iCounter As Integer = 1 To iCount
Object.Call(Me, sDelegateName, [])
Next
End
Public Sub RepeatableOne()
Print "RepeatableOne"
End
Public Sub RepeatableTwo()
Print "RepeatableTwo"
End</lang>
Output:
<pre>
RepeatableOne
RepeatableOne
RepeatableTwo
RepeatableTwo
RepeatableTwo
</pre>
|