Well, I found a "Real2Double" function in the System unit that converts from an old TP 6-byte "real" to an 8-byte double. (Guess I should have looked a little harder, there.) But I'm not seeing anything going the other way. Anyone?

Thanks,

Lowell
At 12:56 PM 9-19-05, Lowell C. Savage wrote:
Has anyone come up with a set of routines for converting between Turbo Pascal's 6-byte "real" format and FPC's real number format?

I am trying to use FPC to update a legacy TP 5.5 program. I've got most of the "major" issues solved and am now finding that I'm having trouble reading legacy data files. Many of these data file are "file of XXXRec" where "XXXRec" is a rather large and complex Record containing strings, integers, bytes, enumerated types, and reals.

My problem is that I am going to need to be able to read these existing files (without modification) into the new version of the program.

I've been able to use the "{$PACKRECORDS 1}" and "{$PACKENUMS 1}" directives to take care of everything else. But now I realize that Turbo Pascal used a 6-byte real representation while FPC uses either a 4 or 8-bit representation.

It appears that I'm going to need to make some kind of a special type, perhaps a packed record with a "byte", a "smallint" and a 4-byte "longword". Then, I read this value from the existing file and convert it into a "real". Then, when I want to write the file (or another file) I convert back to this record type when I fill the record I'm going to write.

Here's a simple program to demonstrate the issue. In Turbo Pascal 5.5 (Downloaded from http://bdn.borland.com/article/0,1410,20803,00.html) this code generates a 12-byte file. FPC generates a 16-byte file. (Actually, the preprocessor directives shown appear to have no effect on this code--not complaining since the docs don't make it appear that it should, just pointing it out.)

Program testrec;
{$IFDEF FPC}
{$MODE TP}
{$PACKRECORDS 1}
{$ENDIF}
type
     realrec = record
        t1 : real;
        t2 : real;
        end;

var
   realfile : file of realrec;
   r : realrec;
begin
   r.t1 := 1.0;
   r.t2 := 2.0;
   assign ( realfile, 'c:\r.rfl' );
   rewrite ( realfile );
   write ( realfile, r );
   close ( realfile );
end.

Any ideas appreciated!

Thanks,

Lowell C. Savage
[EMAIL PROTECTED]
505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)

Lowell C. Savage
[EMAIL PROTECTED]
505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to