Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving and reading data files

Status
Not open for further replies.

gwar2k1

Programmer
Apr 17, 2003
387
GB
OK im no novice with this aspect but for some odd reason, my read procedure isnt doing its job and its rather annoying!

PROCEDURE save_password(user,pword:string; value:longint);

VAR
pin : pword_rec;
pfl : pword_file;

BEGIN
pin.user := user;
pin.pass := pword;
pin.value := value;
assign(pfl,passfile); {constant = 'C:\Data.dat'}
reset(pfl);
seek(pfl,filesize(pfl));
write(pfl,pin);
close(pfl);
END;

That, Im glad to say, works fine. The fact the file size increases is testament to that.
I also have a search procedure that correctly reads the file and does what its meant to with retrieved data...

This however, doesnt work:

PROCEDURE display_users;

VAR
pin : pword_rec;
pfl : pword_file;
y : integer;
s : string;

BEGIN
y := 3;
frame(1,1,80,50);
assign(pfl,userfile);
reset(pfl);
WHILE NOT EOF(pfl) DO
BEGIN
read(pfl,pin);
writexy(2,y,pin.user);
y := y + 1;
str(filezise(pfl),s);
writexy(3,2,s);
END;
END;

S is somehow 1 and no user names are displayed on screen. Im only using the str and filesize to check it works. I know for a fact that there are more than 50 users saved in the file ( i did a repeat loop, adding in users to test another aspect of the program).

This is really puzzling. Can any one explani what's going on please?

TIA


~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."
 
What are the type definitions of pword_rec and pword_file ?


Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
pword_rec = RECORD
user,pass : string;
value : longint;
END;

pword_file = FILE OF pword_rec;

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."
 
(1) How much does the size of your file increase when you add a single new user.
It should increase exactly 516 bytes (2 standard strings and a longint), and if it isn't exactly that value, you have a problem.

(2) Do you mean filezise or filesize in this example?
If you really typed filezise in the str( ) statement, and did something similar somewhere else, it's possible you've defined a type filezise and typecast pfl as one of those, and thus made a mess of the str statment???? unlikely, but....

(3) If you have a search procedure that reads data and interprets it correctly, then the problem MUST be in the procedure that's supposed to print filesize and doesn't. Go back and look at the procedure that Does work, and see how it differs...
 
filesize*

It takes 2 users to raise it 1Kb so yeah I assume its 516b

Ive checked, they're almost identical, except for the search procedure has the IF x = y THEN statement and the read procedure doesnt.

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."
 
Try specifying a fixed length for the string parts:

Code:
pword_rec = RECORD
  user,pass : string[64];
  value     : longint;
END;
 
Are you sure it's the same file? Note that you are using different names in the two routines!
 
Errors in other parts of the program can make strange behaviours, like a loop writing beyond an array size. Then one of the other variables may change randomly.

 
omg ... i probablly had a good reason to add in the userfile constant but then i went to sleep and now ... well its irrelevant and as a result no longer resides in the program ;)

Thanks for pointing out im an idiot ^^;

Sorry for the huge delay, ive been busy recently and Ive just had to format my C:\ so there's been a few problems with s/w installation and such.

Any who THANKS!

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top