Saving and loading UDTs is as simple as passing the UDT to QFileStream or QMemoryStream.
TYPE TTest
S AS STRING*8
N AS INTEGER
END TYPE
DIM Test AS TTest
DIM File AS QFileStream
File.Open("test.txt", fmCreate)
File.WriteUDT(Test)
File.Close
In the above example, 12 bytes was saved to the file test.txt. 8 bytes for the fixed
string S, and 4 bytes for N. To retrieve the UDT, use the method ReadUDT.
File.Open("test.txt", fmOpenRead)
File.ReadUDT(Test)
Saving/Loading arrays is equally easy.
DIM A(1 TO 100) AS LONG
DIM File AS QFileStream
File.Open("test.txt", fmCreate)
File.SaveArray(A(1), 100)
File.Close
The first parameter of SaveArray is the starting array element to save, this could
be any value from 1 to 100 in the above example. The next parameter specifies how many
elements of the array to save. In this case we choose to save all 1..100 elements.
Similarly, we can use LoadArray to retrieve our data:
File.Open("test.txt", fmOpenRead)
File.LoadArray(A(1), 100)
Streams are very popular in most high level languages for file/memory manipulation,
but does take some time to get used to, especially if you're a die-hard BASIC user.