Re: BREAK BY oder ähnlicher Befehl in Purebasic
Verfasst: 18.08.2013 19:40
Mit Pointern geht das so:
Code: Alles auswählen
; Parameter für Liste erzeugen
Structure inhalt
artikel.s
sortiment.s
EndStructure
Global NewList sortiment.inhalt()
Procedure newArt(artikel.s, sortiment.s)
AddElement(sortiment())
sortiment()\artikel = artikel
sortiment()\sortiment = sortiment
EndProcedure
newArt("Salami", "Fleisch")
newArt("Schinken", "Fleisch")
newArt("Apfel", "Obst")
newArt("Birne", "Obst")
newArt("Radeberger", "Bier")
newArt("Becks", "Bier")
SortStructuredList(sortiment(), #PB_Sort_Ascending, OffsetOf(inhalt\sortiment),#PB_String)
Define *previous.inhalt = 0 ;Pointer zum letzten Element, initialisieren mit 0
ForEach sortiment()
If (*previous <> 0 And *previous\sortiment <> sortiment()\sortiment)
Debug *previous\sortiment + " --> " + sortiment()\sortiment
*previous\artikel + " (das letzte!)" ; Nochmal nachträglich ändern
EndIf
*previous = @sortiment() ;Setze Pointer auf das aktuelle Element, damit es im nächsten Durchlauf als das vorherige benutzt werden kann
Next
Debug ""
Debug "Nochmal alle Artikel ausgeben:"
ForEach sortiment()
Debug sortiment()\artikel
Next