Saving and reading data files
Saving and reading data files
(OP)
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
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..."
RE: Saving and reading data files
Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.
RE: Saving and reading data files
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..."
RE: Saving and reading data files
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...
RE: Saving and reading data files
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..."
RE: Saving and reading data files
pword_rec = RECORD
user,pass : string[64];
value : longint;
END;
RE: Saving and reading data files
RE: Saving and reading data files
RE: Saving and reading data files
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..."