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

storing_20structures_20containing_20strings [2018/03/31 13:19]
127.0.0.1 external edit
storing_20structures_20containing_20strings [2018/04/17 18:57]
tbest3112 Added syntax highlighting
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.txt · Last modified: 2018/04/17 18:57 by tbest3112