Assigning a pointer to a structure passed as a parameter to the current value of a list?
Posted: Sat Apr 12, 2025 8:00 pm
I have this test code:
However, if I type Test1 or Test2 in any case, it always shows 0 and doesn't have the correct values assigned to the fields, but it does successfully find it. If I type an invalid name, the invalid name handling triggers. This is utterly baffling.
Code: Select all
EnableExplicit
Structure Thing
Str.s
Num.i
EndStructure
Global NewList Things.Thing()
Macro AddThing(_Str_, _Num_)
AddElement(Things())
Things()\Str = _Str_
Things()\Num = _Num_
EndMacro
AddThing("Test1", 12)
AddThing("Test2", 14)
Procedure.i FindThingByStr(Str$, *Out.Thing)
If Str$ = "" : ProcedureReturn #False : EndIf
Str$ = LCase(Str$)
ForEach Things()
If LCase(Things()\Str) = Str$
*Out = Things()
ProcedureReturn #True
EndIf
Next
ProcedureReturn #False
EndProcedure
OpenConsole()
Print("Type a name: ")
Define Name$ = Input()
Define T.Thing
If FindThingByStr(Name$, @T)
PrintN(T\Str + T\Num)
Else
PrintN(Name$ + " not found.")
EndIf
Input()