Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problems saving from a string list in Delphi

Started by Destriarch Mar 3, 2009 at 8:39 AM 0 replies 550+ views
Original Post
Destriarch
Destriarch
I'm using a string list (in the form of a listbox) to store data from my program, and I want to save parts of that string list to a custom data file. I'm using this simple code to write strings to a file: ------------------------ procedure writetext(filehandle : tfilestream; Text : string); var x : byte; begin x := length(text); filehandle.Write(x,1); filehandle.Write(text,x); end; function readtext(filehandle : tfilestream) : string; var x : byte; begin filehandle.Read(x,1); filehandle.Read(result,x); end; ------------------------ Now, when I save from a regular string this works fine, but when I save from a string list entry and try and load it again later, I get gibberish, often not even from the file I just saved. I have no idea why this is happening. I've tried passing the string from the list into a temporary holding string and saving that, but the results are the same. Here's my saving code. The list box is called 'skills' and the file 'output'. Temp is a temporary string variable and X is a byte. ------------------------ try x := 3; temp := skills.items[4]; writetext(output,temp); output.Write(x,1); writetext(output,'[End]'); finally output.free; end; ------------------------ And here's the loading code: ------------------------ try temp := readtext(output); while temp <> '[End]' do begin output.Read(x,1); skills.Items[skills.items.IndexOf(temp)+1] := inttostr(x); temp := readtext(output); end; finally output.free; end; ------------------------ Can anyone tell me what I'm doing wrong? It's driving me barmy! -Ash

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.