| Wolfi30 
 
 
 Anmeldungsdatum: 17.08.2007
 Beiträge: 38
 
 
 | 
			
				|  Verfasst am: 25.11.2007, 14:19    Titel: Kleine OOP-Liste |   |  
				| 
 |  
				| Hallo, 
 hab hier mal der Übung wegen eine kleine Liste in Freebasic-OOP aufgebaut!
 Mir ist dabei aufgefallen, das eine deklarierte Variable in einer FOR-Schleife in einer property-Anweisung nicht erkannt wird! Compiler zeigt mir "Variable not declared" an. Hab dann mit der while-wend variante gearbeitet und es ging dann!
 Deklariere ich die Variable direkt in der property-Anweisung erkennt die For-Schleife die Variable an!
 
 Hier mal der Code mit einem Beispiel
 
 
 
  	  | Code: |  	  | Type TListValue pValue As UByte
 pRev As TListValue Ptr
 pNext As TListValue Ptr
 End Type
 
 Type TList
 
 Declare Constructor()
 Declare Destructor()
 
 Declare Property GetStartAdr() As TListValue Ptr
 Declare Property Value() As UByte
 Declare Property Value(ByVal wert As UByte)
 Declare Property ListCount() As UInteger
 Declare Property DelListPos(ByVal position As UInteger)
 Declare Property InsertPos(ByVal position As UInteger)
 Declare Property GotoListPos(ByVal position As UInteger)
 Declare Sub Start()
 Declare Sub NewList()
 Declare Sub NextValue()
 Declare Sub PrevValue()
 
 
 Private:
 
 i As UInteger
 count As uInteger
 pStart As TListValue Ptr
 pIst As TListValue ptr
 pMerke As TListValue Ptr
 pMerkeNext As TListValue Ptr
 pDel As TListValue Ptr
 
 End Type
 
 Constructor TList()
 
 pStart=allocate(SizeOf(TListValue))
 pStart->pRev=0
 pIst=pStart
 count+=1
 
 End Constructor
 
 Destructor TList()
 
 pMerke=pStart
 While pMerke->pNext <> 0
 pMerkeNext=pMerke->pNext
 deallocate(pMerke)
 pMerke=pMerkeNext
 Wend
 DeAllocate(pMerke)
 count=0
 End Destructor
 
 Property TList.GetStartAdr() As TListValue Ptr
 
 Property=pStart
 
 End Property
 
 Property TList.Value() As UByte
 
 Property=pIst->pValue
 
 End Property
 
 Property TList.Value(ByVal wert As UByte)
 
 pIst->pValue=wert
 
 End Property
 
 Property TList.ListCount() As UInteger
 
 Property=count
 
 End Property
 
 Property TList.DelListPos(ByVal position As UInteger)
 
 pMerke=pStart
 
 If position = 1 Then
 
 pDel=pMerke
 pMerke=pMerke->pNext
 pMerke->pRev=0
 pStart=pMerke
 DeAllocate(pDel)
 count-=1
 
 ElseIf position = count Then
 
 While pMerke->pNext <> 0
 pMerke=pMerke->pNext
 Wend
 
 pDel=pMerke
 pMerke=pMerke->pRev
 pMerke->pNext=0
 DeAllocate(pDel)
 count-=1
 
 ElseIf position > count Then
 
 Print "Error position > ListCount"
 
 Else
 
 i=1
 While i <= position-1
 pMerke=pMerke->pNext
 i+=1
 Wend
 
 pDel=pMerke
 pMerke=pDel->pRev
 pMerkeNext=pDel->pNext
 pMerke->pNext=pMerkeNext
 pMerkeNext->pRev=pMerke
 DeAllocate(pDel)
 count-=1
 
 EndIf
 
 End Property
 
 Property TList.InsertPos(ByVal position As UInteger)
 
 pMerke=Allocate(SizeOf(TListValue))
 
 If position=1 Then
 
 pMerke->pRev=0
 pMerke->pNext=pStart
 pStart->pRev=pMerke
 pStart=pMerke
 Start()
 count+=1
 
 Else
 
 pIst=pMerke
 
 pMerke=pStart
 
 i=1
 While i <= position-2
 pMerke=pMerke->pNext
 i+=1
 Wend
 
 pMerkeNext=pMerke->pNext
 
 pMerke->pNext=pIst
 pMerkeNext->pRev=pIst
 
 pIst->pRev=pMerke
 pIst->pNext=pMerkeNext
 
 count+=1
 
 EndIf
 
 
 
 End Property
 
 Property TList.GotoListPos(ByVal position As UInteger)
 
 Start()
 i=1
 While i <= position-1
 pIst=pIst->pNext
 i+=1
 Wend
 
 End Property
 
 Sub TList.Start()
 
 pIst=pStart
 
 End Sub
 
 Sub TList.NewList()
 
 pIst->pNext=Allocate(SizeOf(TListValue))
 pMerke=pIst
 pIst=pIst->pNext
 pIst->pRev=pMerke
 pIst->pNext=0
 count+=1
 
 End Sub
 
 Sub TList.NextValue()
 
 If pIst->pNext <> 0 Then
 pIst=pIst->pNext
 EndIf
 
 End Sub
 
 Sub TList.PrevValue()
 
 If pIst->pRev <> 0 Then
 pIst=pIst->pRev
 EndIf
 
 End Sub
 
 
 Dim Liste As TList
 Dim i As UInteger
 
 Liste.Value=10
 
 For i=2 To 10
 Liste.NewList
 Liste.Value=i*10
 Next
 
 Liste.Start
 
 For i=1 To Liste.ListCount
 ? Liste.Value
 Liste.NextValue
 Next
 
 Sleep
 ?
 
 Liste.InsertPos=3
 Liste.Value=25
 Liste.Start
 
 For i=1 To Liste.ListCount
 ? Liste.Value
 Liste.NextValue
 Next
 
 Sleep
 ?
 
 Liste.DelListPos=3
 Liste.Start
 
 For i=1 To Liste.ListCount
 ? Liste.Value
 Liste.NextValue
 Next
 
 Sleep
 | 
 
 Gruß Wolfi
 |  |