TList

Started by Baggey, December 20, 2024, 09:55:13

Previous topic - Next topic

Baggey

Can Tlist's only contain bytes if so how? It only seems that i can add strings? :-[

I thought the idea of an object list is so you can put anything in the List!?

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Dabz

#1
Yeah, that is because a string is actually "an object", and TList only works with objects, for a sanity check, you can see, strings have members:

Print "hello".ToUpper()

Some handy ones too mind:  Strings ยท BlitzMax

Anyway, since they are not a data type like your thinking, which is why a string works, and an Int doesnt, you can shuffle an int into a type and create objects around it, which then you can store and retrieve in a list:

Type TMyType
Field anInt:Int
EndType

Local list:TList = New TList

Local newObject:TMyType

For Local loop:Int = 1 To 10
newObject = New TMyType
newObject.anInt = loop
list.AddLast(newObject)
Next

For Local myTypeObject:TMyType = EachIn list
Print myTypeObject.anInt
Next

Print "End"

Voila!!!

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Dabz

Or, another way which is generally the accepted practice of creating types using a Create method:

Type TMyType
Field anInt:Int

Method Create:TMyType(someInt)
Local newObject:TMyType = New TMyType
newObject.anInt = someInt
Return(newObject)
End Method
EndType

Local list:TList = New TList

For Local loop:Int = 1 To 10
list.AddLast(New TMyType.Create(loop))
Next

For Local myTypeObject:TMyType = EachIn list
Print myTypeObject.anInt
Next

Print "End"

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Derron

primitives need to be wrapped (so "int, long, uint, ulong, byte ..."), structs need to be wrapped too ... and then you can place them into a TList.


bye
Ron

Baggey

Quote from: Derron on December 20, 2024, 16:04:33primitives need to be wrapped (so "int, long, uint, ulong, byte ..."), structs need to be wrapped too ... and then you can place them into a TList.


bye
Ron
Hi @Derron, Thankyou for the reply. You forget im a hobbyist programmer.

So i have no idea what primitives, structs and being wrapped means :-[

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Midimaster

Primitives are the "number"-variable types. As he said: BYTE SHORT INT FLOAT, etc...

wrapping is pack the variable into another, like Dabz showed it.

Here is more simple example:


' instead of X:Byte = 5 you wrap the byte into any Type:
Local X:TWrap = New TWrap(5)
' now the 5 is "wrapped" into a home made type

' now you need to use a dot-name to get the value of X
Print X.Value


Type TWrap
    Field Value:Byte

    Method New(v:Byte)
        Value = v
    End Method
End Type

' the advantage is that you now can add this to a Tlist:

List.AddLast X
...back from North Pole.

Baggey

Thankyou for all the replys and help!

Ive taken on everybody's help and incorporated it in my way! This is into today's coding efforts for my Alien Dropout Remake ;)

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Dabz

Quote from: Baggey on December 20, 2024, 16:46:14
Quote from: Derron on December 20, 2024, 16:04:33primitives need to be wrapped (so "int, long, uint, ulong, byte ..."), structs need to be wrapped too ... and then you can place them into a TList.


bye
Ron
Hi @Derron, Thankyou for the reply. You forget im a hobbyist programmer.

So i have no idea what primitives, structs and being wrapped means :-[

Kind Regards Baggey

So am I, but you get used to the terminology, I wouldnt worry about it, tech is moving all the time as well, and new buzz words come out. Reminds me when me and an indie called James Mintram (At first with a surname like that I thought he was taking the wee wee), went to a DevCon in Newcastle, a mix of indies and *Cough* AAA, anyway, I ended up talking to this fella who looked like Jesse from Storage Wars. He worked for Ubisoft, had something to do with the servers, but when he started getting right into it... Honestly, my ears stopped listening and I just saw his lips move... I never had a fooking clue what he was on about! :D

James noticed and came over to rescue me, he seemed to know WTF this fella was on about it, and left them and proceeded to talk to two lads who worked on Settlers 7, which led me to taking the piss out of them for making and releasing broken software! :D

Goodnight that, I ended up bloody minging!!! :D

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Baggey

@Dabz 

I used to know a Wane Kerr for real! ;D It used to crack me up everytime his name came over the Tanoy :))

Such Fun we had!?

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!