If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

String-in-String-Pointers?

Today I need some idea or advice how to get the following done:

I'm creating own UI for my current app. Now I want to create a listbox-alike control that shall be multiple usable and show different arrays of strings.
So for example the box is supposed to show a list of files, stored to

Dim sFile() as String

and the next time/another listbox is to show a list of sCountries() or sNames() or whatever. The problem is, how can I store a pointer to the correct array, so the listbox-drawing-routine "knows" which array and how many items to fill in, since the arrays are all dynamic string-arrays and they might change their location in memory when redimensioned?

Is there a cool way alike calling functions? - So I could store the arrays name (!) in another string like this:

'...
Gadget(%gListboxFile).ArrayToUse = "sFile()"
Gadget(%gListboxName).ArrayToUse = "sName()"
'...
Sub DrawListbox(Byval Index as Long)
Static i as Long
' -- pseudo-code:
Local sString() Alias Gadget(Index).ArrayToUse As String
For i = 1 to Ubound(sString)
PrintL sString(i)
Next i
End Sub

Wow Renč, you always find some interesting ways of doing things Alias of a variable name using a string is something I really like.
Do not know how to implement but I like the idea!
Maybe in near future ... who knows

Back to what could be done right now, it comes to my mind 2 quick ways:

BUT ATTENTION: there is a BUG in thinCore.dll also in versions previous 1.9.4It free memory also for variables created using DIM ... AT ... when variables are strings while it should not do it!
I do not understand how I could have introduced such a stupid bug ????????So please get attached thinCore.dll and place into your \thinBasic\ directory before executing above examples

OK, thanks Eros, I'm alway happy to have and use the latest available Version, so I got the feeling my computer understands an up-to-date language.

Your second example comes closest to my needs but the point is, I wanted to get around using "Select Case" and "If" as much as possible and prefer to give quick straight orders rather than cumbersome comparing before. It'll do the job for my current project- but not as flexible that I could use the handling for Gadget "listbox" from another script without any changes.

[goodMorningThoughts]
That's why I think, it would be great improvement if thinBasic could "recognize" a variable from it's name - and not just through a pointer - as it can do already with subs & functions. It would make computers that run thinBasic real smart-asses compared to others and might start a(n/r)evolution in basic programming since it's real understandable, easy Basic. And I'm unable to predict how many ways people find to use it, if they got the possibillities.

A 2-year old child recognizes stuff from names after pointing to it a few times - and not just from looks - it's a precondition to thinking.
- Pointers we have...

A 4-year old will understand that there are often more than just one word for the same thing.
- Virtual Variables we have also...

A 6-year old can read his and others names and "imagine" a face to the name...
- hmm,...

Grown-ups don't care what others do nor think, they make up their own mind...
- yep,
[/goodMorningThoughts]

Some small questions I wonder about: to ReDim uses up lots of time. How is that with virtual variables?
It should be pretty much faster since it doesn't really allocate additional space - but I'm not sure about it...
and additional to that:

Is possible to ReDim the size of the real variable through the virtual one?

Just because fits this topic, I got some new weired stuff in mind - related to that String "somewhat special inside"-thing.

Because currently I think about FAST loading meshes into TBGL in any way - don't care how - I came to the conclusion the fastest would be to pump the data from HD directly to a displaylist.
small example here some code snippet to visualize what data to await:

I already made a routine to save my data this way (plain *.txt-file) so user can import his 3d-stuff directly to his script by copy & paste from texteditor.

However - if I save the data to binary - which might be the fastest way to load & save - I would have to run through my binary data and convert somehow to parameters for all those TBGL-Methods which would use somewhat of calculation-time and a few steps from binary saved data to create valid codelines in the right order.

Now my thoughts going to

local myFile as Dword = File_Open(fName, "INPUT")
local sRead as String
'...
While Not File_EOF(myFile)
sRead = File_LineInput(myFile)
' now sRead holds one line as in code above...
' Call_IfExists sRead ??? - naa - almost...
' because i had to make Val() from the parameters,
' that would mean to parse the line sRead in advance
' no - I think about some
Execute$(sRead)
Wend

so basically - treat the string-content as it would be a thinBasic-code-line in the script.
I know it will not work with Select Case nor multiline-if, so just one statement per line is limit i think,
-variables inside or constants ? - complicated but maybe...

That way I could save data to plain scriptlines in the order they shall be executed without any need to order them again. Of course I won't read line-by-line as in the example, but so example becomes clearer. I could give the statements directly from file to tB to be executed.
The lines would not stay in memory forever as they would in an include-unit-file and I think there are more uses possible, imagine to save all visual-designer-stuff somehow like this, or other run-once-at-startup-stuff...all lines from top to bottom get executed once - and then they're done & gone from memory...

As usual the programmer is responsible which strings shall be executed here.
maybe can be more versions of this:
to CORE/String-Functions:
Execute$(sString) as in this example
to CORE/String
ExecuteArray$(sStringArray[,startIndex[,endIndex]])
to CORE/String
ExecuteParse$(sString) ' $crlf as delimiter expected i'd say...

to FILE-Module which directly does
LineInput + executes it in one call.
File_ExecuteLine$(nFilenum) ' similar to File_LineInput + Execute$()
File_ExecuteFile$(sFilename) ' similar to File_Load + ExecuteParse$()

Not just around the corner and I cannot still promise anything but I think there will be the possibility to load an external text file on request when needed and interpret it as "on the fly script source code" like it would be part of the script itself.

In my mind I still have to find solutions for few technical problems but at first sight it seems doable.

OK, I would suggest new file-extension for these too, so thinAir will open it for edit from the built-in explorer and not just through File\Open from menu to open a *.txt -file. maybe *.tBasicE or *.TBTxt
- or make thinAir display & open *.txt from list below explorer-treeview...would be nice to use thinAir for quick writing/changing ReadMe.txt without changing to notepad also.

I got some solution in the meantime to get String-In-String-Pointers done - so I am able to assign some UDT-variable to some object - in this example is a small listview just for demonstration-purpose. You'll need the latest thinCore.dll to run this. Run NewTest.tBasic but put SHEET.tBasicU into the same folder.

PS. I could not find built-in Equates to specify var-types - I think there should be some...
and- in SHEET_AddHeader could be some Sheet(Index).Width += nChars * something + some border - but I did not use it here, neither did I use flags as %align_left or %align_right here to not too complicate it.

The 169-lines Sheet-Unit consists of declarations for the functions and three subs to handle the sheets.

Variables ByString work already but still urge for some solution for the following.

Some users might remember I was creating some UI-controls that have different properties. The solution was to use Union, but this wastes a lot of memory since all controls use as much as the largest control - the one with the most properties- does.

Now I attempt to Extend single elements of my main-CTRL/Gadget-Array as in this simplyfied example, so imagine Subtype1 would be a button or timer and the other one would be a property-list or grid or whatever...

Uses "Console"
Alias DWord As SomeSubType
Type t_mySubType1
A As Long
B As Byte
C As DWord
End Type
Type t_mySubType2
A As Long
B As Byte
C As DWord
D As Double
End Type
Type t_myMainType
Style As String
X As Long
Y As Long
pST As SomeSubType
End Type
Dim foo(5) As t_myMainType
foo(1).Style = "t_mySubtype1"
foo(1).pST = HEAP_Alloc(SizeOf(t_mySubtype1))
foo(2).Style = "t_mySubtype2"
foo(2).pST = HEAP_Alloc(SizeOf(t_mySubtype2))

fine till here- you see what I'm up to...

' now I'm stuck...
' I would need a method to get the UDT-Structure
' from the name stored in foo().Style
' would have to work as follows:
foo(1).Style = "t_mySubtype1"
foo(1).pST = HEAP_Alloc(SizeOf( ByString(foo(1).Style) )
' and also will not work
Dim Subtype As ByString(foo(1).Style) At foo(1).pST
' because
Dim Subtype As ByString(foo(2).Style) At foo(2).pST
' will now throw Error: Variable already exists
' also
ReDim Subtype As ByString(foo(2).Style) At foo(2).pST
' is not possible because SubType is not an array...
Reset Subtype As ByString(foo(2).Style) At foo(2).pST
' also not possible...
WaitKey

I need something that holds the information of the UDT-structure. In thinCore.inc I've not found such thing
Also would be great if a virtual layover could be changed in Type somehow