Page 1 of 1

Streams...

PostPosted: September 26th, 2006, 6:41 pm
by rhartl
Can someone help me figure out what I am doing wrong. I am trying to write the contents of an object to a file using TFilestream. The following code writes without blowing up, but when reading the object back in I get a list that is not correct, it has an extra string at the top with a nonsense character.

writing...

Try
AFile := TFileStream.Create(FileName,fmCreate);
Except
MessageDlg('Blew up',mtError,[mbOk],0);
Exit;
End;

FKeyWords.SavetoStream(AFile);

AFile.Free;


reading...

Try
AFile := TFileStream.Create(FileName,fmOpenRead);
Except
MessageDlg('Blew up',mtError,[mbOk],0);
Exit;
End;

FKeyWords.LoadFromStream(AFile);

AFile.Free;

-- Rich

PostPosted: September 26th, 2006, 8:09 pm
by Johnny_Bit
Details man, details! we need details! So help us help you and give us as much data as possibe, qg. contents of file, contents of object, contents of this, contents of that, what is what, types of data and so on. You feelin' me?

Sorry...

PostPosted: September 26th, 2006, 8:39 pm
by rhartl
FKeyWords is a TStingList type. It initially contains single random words read from a text file. I then try to write using TFilestream the contents of FKeyWords and read them back out again. FKeywords is part of another object that wraps several lists together. Is that enough?

-- Rich

PostPosted: September 26th, 2006, 9:06 pm
by Kambiz
According to the information you have provided, your code should work.

Maybe if you can provide a complete code, we can figure out the problem.