Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

FuncSubPointer Vergleich

Uploader:RedakteurMOD
Datum/Zeit:11.06.2011 19:40:30

'Beispiel für Function- und Subpointer im Zusammenhang mit UDTs

'Auskommentieren oder verändern um Functionvariante zu testen, sonst Subvariante
#Define subVariante

#Ifdef subVariante

Type foo
    dummy As Integer = 5

    Declare Sub bar ()
    Declare Static Sub bar (baz As foo)

    tFunc As Sub ()
End Type


Sub foo.bar ()
    Print this.dummy
End Sub

Sub foo.bar (baz As foo)
    baz.bar()
End Sub

Sub sonstiges ()
    Print 7
End Sub

Dim As foo tester
tester.tFunc = @sonstiges

Dim As Sub (baz As foo) testFunc1 = @foo.bar
Dim As Sub () testFunc2 = @sonstiges

testFunc1(tester)
testFunc2()
tester.tFunc()
Sleep



#Else



Type foo
    dummy As Integer = 5

    Declare Function bar () As Integer
    Declare Static Function bar (baz As foo) As Integer

    tFunc As Function () As Integer
End Type


Function foo.bar () As Integer
    Return this.dummy
End Function

Function foo.bar (baz As foo) As Integer
    Return baz.bar()
End Function

Function sonstiges () As Integer
    Return 7
End Function

Dim As foo tester
tester.tFunc = @sonstiges

Dim As Function (baz As foo) As Integer testFunc1 = @foo.bar
Dim As Function () As Integer testFunc2 = @sonstiges

Print testFunc1(tester)
Print testFunc2()
Print tester.tFunc()
Sleep

#EndIf