Hey there. Here is your code more carefully formatted and with some commentary.
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
Tperson = record
Name: String;
Dateofbirth: TDateTime;
end;
var
s: string;
FileA: textfile;
datestring: string;
personarray: array [1..5] of Tperson; // very good
personinfo: Tperson;
I: Integer;
begin
// You only need to set this global value once
ShortDateFormat := 'd/mm/yyyy';
// Good
Assign(FileA,'PeopleInformation.txt');
// The following reads each line of the file but
// does nothing with it...
Reset(FileA);
while not EOF(FileA) do
begin
Readln(FileA,s);
// See note 1
end;
close(FileA);
// The following is a loop that properly reads each
// record from file. However, like the first loop's
// s:string variable, the information is never used;
// it is forgotten the next time through the loop.
// See note 2
Reset (FileA);
while not EOF(FileA) do
begin
Readln (FileA,personinfo.name);
Readln (FileA,datestring);
personinfo.Dateofbirth:=strToDate(datestring);
Readln ( FileA );
end;
// Here you try to print a variable you never initialized.
// See note 3
writeln (personarray[1].name, personarray[1].Dateofbirth);
// Wait for the user to press ENTER before terminating
readln;
end.
Note 1
Perhaps you made this loop because you wanted to see the file before putting it in a TPerson record? If so, replace the
// See note 1
coment with: writeln( s );
Otherwise, you keep givings a new value each time through the loop but you never actually use it. Neither s nor the loop have any purpose --you could just delete it and the code would work the same.
Note 2
As already noted, you are making the same error here with personinfo as you did with s above. Each time through the loop you initialize it properly, but you never use it before initializing it again with a new person's data.
I think what you wanted to do is replace
personinfo.<em>something</em>
with personarray[ i ].<em>something</em>
This means though that you will have to usei as well. Before starting the loop set it to 1 and increment it by one at the end of each loop.
Note 3
You should always give a variable a value before you use it. Since you did not store your records in personarray (see note 2), but only in personinfo, the only variable that has information read from file is personinfo, and it is only the very last record in the file (Ross Harrison).
The problem you are having with the funny "00000000E+0000" output is this: since you never gave the personarray[1] record a value, the Name string is the empty string ('', i.e. a string with no characters in it), and the DateOfBirth is zero. So, when you ask to
writeln( <em>myperson</em>.Name, <em>myperson</em>.DateOfBirth );
it does just that, first printing
then printing 00000000E+0000 TDateTime is stored as a floating point double, so that is why the weird output. Remember you must use the StrToDate and DateToStr functions to convert a string to or from a tDateTime.
Hope this helps.