How to have dynamic sized arrays in types

Blitz3D Forums/Blitz3D Programming/How to have dynamic sized arrays in types

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

It already works (I can already add tradable wares to any station):
Type TWare
	Field prev.TWare
	Field nex.TWare
	Field value.TWareType
	Field price%
End Type

Type TStation
	Field Name$
	Field WareList.TWare ; This pointer specifies the start of a custom linked list of tradable wares (the list can be as long as needed)
End Type



Function AddWareToStation(Station.TStation, WareTypeName$, price%)
	; Find the last TWare (the last TWare instance of the chain)
	Local LastTWare.TWare = FindLastTWare(Station)
	Local TempTWare.TWare

	; If the station already has a ware, do the first part (add a ware to the chain), else the second part (create the first ware)
	If Station\WareList <> Null Then
		; Temporarily store the address of the last TWare in the chain (is needed to set the "prev" field for a new TWare
		TempTWare = LastTWare

		; Set the "nex" field of the last TWare to point to a new TWare
		LastTWare\nex = New TWare
		; Get the address of the newly added TWare
		LastTWare = LastTWare\nex

		; Set fields for this new TWare
		LastTWare\prev = TempTWare
		; Set the price for the new TWare
		LastTWare\price% = price
		; Let the TWare point to a specific TWareType
		LastTWare\value = FindTWareType(WareTypeName$)
	Else
		; Let the WareList field point to a new TWare
		Station\WareList = New TWare
		; Set the price for this new TWare
		Station\WareList\price% = price
		; Let the TWare point to a specific TWareType
		Station\WareList\value = FindTWareType(WareTypeName$)
	EndIf
End Function

Function FindLastTWare.TWare(Station.TStation)
	Local a.TWare

	If Station\WareList <> Null Then
		a = Station\WareList

		While a\nex <> Null
			a = a\nex
		Wend
	EndIf

	Return a
End Function


Is this good coding?