Good afternoon all,
I have a number of typed binary files created in a program written in an old version of Turbo Pascal (7.0). These files consist of records in the following format:
type
info = RECORD
string1, string2, string3, string4 : string;
int : integer;
end;
I am now working in FreePascal and I'm trying to read these old files and write them out to plain text files. Since FreePascal's strings can't be used in files I tried using ShortStrings and also string[255] - these are probably equivalent - but each time, the resulting text file is garbled with strange characters jumbled in with some of the data I know is in the old files.
The code I'm using is roughly this:
var
inforec : info;
oldfile : file of info;
newfile : text;
i, maxrecords : integer;
begin
assign(oldfile, 'oldfilename');
reset(oldfile);
assign(newfile, 'newfilename.txt');
rewrite(newfile);
maxrecords := filesize(oldfile);
for(i := 1 to maxrecords) do
begin
read(oldfile, inforec);
writeln(newfile, inforec.string1);
writeln(newfile, inforec.string2);
writeln(newfile, inforec.string3);
writeln(newfile, inforec.string4);
writeln(newfile, inforec.int);
end;
close(newfile);
end.
I'm probably missing something really obvious but whether I use ShortStrings or string[255] in my record definition I get the same garbled results in my text file (I know the files are not damaged because I can still read them using the old program on a DOS VM).
Does anyone have any suggestions as to what I might be doing wrong?
EDIT: Realised I posted this in the wrong section. Mods can you please move this topic to the FreePascal General board? Thanks!