I'm getting a I/O error 104 when reading TP
(a file containing a Picture name):
procedure TfrmAvatar.FormShow(Sender: TObject);
var
sLocation: String;
TU, TP: textfile;
sUser: string;
iTemp: integer;
begin
sLocation := ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0))));
AssignFile(TU, (sLocation '\Username.txt'));
Reset(TU);
Readln(TU, sUser);
edtUser.Text := sUser;
CloseFile(TU);
AssignFile(TP, (sLocation '\Profile.txt'));
Reset(TP);
Readln(TU, sUser); //Getting 104 here on read
ShowMessage(sLocation sUser);
imgAvatar.Picture.LoadFromFile(sLocation sUser);
CloseFile(TP);
end;
Like I said above, I'm simply reading one line from an assigned file TP
. I don't see where my mistake is. If it is obvious, just let me know.
CodePudding user response:
You are reading from a closed file handle (TU
).
What you want to do is
readln(TP, suser);