Streams...

Please discuss general Delphi programming topics here.

Streams...

Postby rhartl » September 26th, 2006, 6:41 pm

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
rhartl
Active Member
Active Member
 
Posts: 11
Joined: June 12th, 2006, 2:30 am

Postby Johnny_Bit » September 26th, 2006, 8:09 pm

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?
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Sorry...

Postby rhartl » September 26th, 2006, 8:39 pm

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
rhartl
Active Member
Active Member
 
Posts: 11
Joined: June 12th, 2006, 2:30 am

Postby Kambiz » September 26th, 2006, 9:06 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron