How do you pass a structure via a pointer to a procedure?
I want to be able to add/edit/delete to/from a structured list without making everything global all the time.
I tried the below just as a start to access a structure (and I want to access a list later) but I get a "Pointer is Null" as I don't know what I am doing at all.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!Please visit my YouTube Channel
Structure Animal
Name.s
Speed.l
EndStructure
Procedure SortAnimalsBySpeed(List Animals.Animal())
SortStructuredList(Animals(), 0, OffsetOf(Animal\Speed), TypeOf(Animal\Speed))
EndProcedure
Procedure AddAnimal(List Animals.Animal(), Name.s, Speed.l)
AddElement(Animals())
Animals()\Name = Name
Animals()\Speed = Speed
EndProcedure
Procedure Main()
; non global list named Animals
Protected NewList Animals.Animal()
AddAnimal(Animals(), "Tiger", 10)
AddAnimal(Animals(), "Jaguar", 40)
AddAnimal(Animals(), "Zebra", 30)
SortAnimalsBySpeed(Animals())
ForEach Animals()
Debug Animals()\Name+" - Speed: "+Str(Animals()\Speed)
Next
EndProcedure
Main()
Holy cow, I did not know you could do that!! I looked through the manual but could not find this referenced anywhere (predictably as I didn't know what I was looking for as usual) but this will simplify things a lot.
Thank you.
And thanks to Demivec and TI-994A as well.
Now I suppose I have to actually start writing code instead of just designing forms (groaan).
P.S TI-994A, I know it's overkill but I am adding your banner that you made me to all of my programs as I like them and they are for my use anyway (heheheh).
Fangbeast wrote:...your banner that you made me...
So, it's your banner!
I'm really glad you like it.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!Please visit my YouTube Channel
*Foo.Testing = AllocateStructure(Testing) ;this command also initializes the structure
It should be noted that the AllocateStructure() function performs two processes; it allocates the memory required for the structure, and initializes arrays, lists, or maps in the structure, if any.
As such, for structures that don't utilise arrays, lists, or maps, the AllocateMemory() function would suffice.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!Please visit my YouTube Channel