User Tools

Site Tools


storing_20structures_20containing_20strings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
storing_20structures_20containing_20strings [2018/03/31 13:19] – external edit 127.0.0.1storing_20structures_20containing_20strings [2024/01/05 00:21] (current) – external edit 127.0.0.1
Line 4: Line 4:
 ===== Writing the structure ===== ===== Writing the structure =====
 \\  To copy the strings into temporary variables, which should be made **LOCAL** inside your save routine, and clear the strings use code similar to the following:\\ \\  \\  To copy the strings into temporary variables, which should be made **LOCAL** inside your save routine, and clear the strings use code similar to the following:\\ \\ 
 +<code bb4w>
         temp1$ = struct.string1$         temp1$ = struct.string1$
         temp2$ = struct.string2$         temp2$ = struct.string2$
-        etc...+        REM etc...
         struct.string1$ = ""         struct.string1$ = ""
         struct.string2$ = ""         struct.string2$ = ""
-        etc...+        REM etc... 
 +</code>
 \\  Here each string in the structure is copied into a temporary string and each string in the structure is set to a NULL string (**""**). It is now safe to write the structure and the string data to the file:\\ \\  \\  Here each string in the structure is copied into a temporary string and each string in the structure is set to a NULL string (**""**). It is now safe to write the structure and the string data to the file:\\ \\ 
 +<code bb4w>
         PTR#file% = temp%         PTR#file% = temp%
         SYS "WriteFile", @hfile%(file%), struct{}, !!^struct{}, ^temp%, 0         SYS "WriteFile", @hfile%(file%), struct{}, !!^struct{}, ^temp%, 0
         PRINT#file%, temp1$, temp2$...         PRINT#file%, temp1$, temp2$...
 +</code>
 \\  Here the file buffers are flushed, the structure is written to the file and the temporary copy of each string is written to the file.\\ \\  To copy the strings back into the structure use code similar to the following:\\ \\  \\  Here the file buffers are flushed, the structure is written to the file and the temporary copy of each string is written to the file.\\ \\  To copy the strings back into the structure use code similar to the following:\\ \\ 
 +<code bb4w>
         struct.string1$ = temp1$         struct.string1$ = temp1$
         struct.string2$ = temp2$         struct.string2$ = temp2$
-        etc...+        REM etc... 
 +</code>
 \\  \\ 
 ==== Reading the structure ==== ==== Reading the structure ====
 \\  To load the structure from the file use code similar to the following:\\ \\  \\  To load the structure from the file use code similar to the following:\\ \\ 
 +<code bb4w>
         PTR#file% = PTR#file%         PTR#file% = PTR#file%
         SYS "ReadFile", @hfile%(file%), struct{}, !!^struct{}, ^temp%, 0         SYS "ReadFile", @hfile%(file%), struct{}, !!^struct{}, ^temp%, 0
         INPUT#file%, struct.string1$, struct.string2$...         INPUT#file%, struct.string1$, struct.string2$...
 +</code>
 \\  Here we flush BASIC's file buffers, call "ReadFile" to read the structure from the file and use **INPUT#** to load the strings from the file. \\  Here we flush BASIC's file buffers, call "ReadFile" to read the structure from the file and use **INPUT#** to load the strings from the file.
storing_20structures_20containing_20strings.1522502384.txt.gz · Last modified: 2024/01/05 00:16 (external edit)