Have your got old Turbo Pascal 3.0 code hanging around since before
Visual
Basic was only a glint in Bill Gates eye? Well it is time
to port this
code to Turbo Pascal 7.0 or maybe even Delphi! Just think,
no more 64kb
code limit, and a real IDE in which to develop your application.
The MTurbo3 is a small unit but it is a beauty. It provides
you with the
following procedures and functions that behave exactly as their
Turbo
Pascal 3.0 equivalents. Now porting old code becomes just
a search
and replace operation!
Installing
----------
There is no install procedure. Simply copy mturbo3.pas and
mturbo3.tpu
to where you need it and include a "uses mturbo3;" in your source
code.
Video procedures
----------------
As you know Borland changed the definition of the xVideo functions
with
Turbo Pascal version 4. These replacements will behave as
the old Turbo 3
functions, including the yellow-as-highlight character (or white
for b&w
modes).
procedure HighVideo3
procedure LowVideo3
procedure NormVideo3
procedure TextMode3 (mode: integer)
Memory function
---------------
As you know 'MaxAvail' returns the amount of free memory measured
in
16-byte paragraphs. TP4 changed MaxAvail to 'bytes', but
now you can
leave your logic alone. Just call...
function MaxAvail3: integer
Turbo Pascal 3.0 BCD Form function
----------------------------------
Did you enjoy the 'Form' function? Well, Pascal didn't allow
me to
do a variable number of argument function for this unit, but I
provide
these functions, that work just as the Form function.
function FormReal(fmt : string; rval : double): string;
function FormInteger(fmt : string; ival : integer): string;
function FormLongint(fmt : string; lval : longint): string;
function FormString(fmt : string; sval : string): string;
BCD Reals
---------
If your porting effort always seemed stymied by a choice back in
1985
to write 10 byte BCD reals to disk files, don't feel bad, I did
the
same thing! Here is what you need to address the problem.
In Turbo Pascal 7.0, Borland provided a real data type called 'Extended'
that is 10 bytes in size. The internal format is completely
different
than BCD reals, but with the size the same you can replace BCD
reals
within Pascal records with Extended data type and your records
will
still align on disk. Now all you have to do is convert the
BCD real
read from disk to Extended. Here are your procedures and
functions...
procedure BCDToStr (R : Extended; Var S : String);
procedure StrToBCD (S : String; Var R : Extended);
function BCDToExtended (R : BCDReal) : Extended;
function ExtendedToBCD (R : Extended) : BCDReal;
function BCDToDouble (R : BCDReal) : Double;
function DoubleToBCD (R : Double)
: BCDReal;
One caveat to be aware of is when you call ExtendedToBCD your 'extended'
real must have an exponent of 63 or less, otherwise a Floating
point
overflow will occur.
Example
TP3 code...
type
rt = record
f1
: real;
f2
: integer;
f3
: real;
end;
var
r : rt;
rfile : file of rt;
read(rfile,r);
{ process r...}
write(rfile,r);
This becomes....
uses
MTurbo3;
type
rt = record
f1
: BCDReal; { change data type here }
f2
: integer;
f3
: BCDReal; { and here..}
end;
var
r : rt;
rfile : file of rt;
etmp: extended;
read(rfile,r);
etmp := BCDToExtended(r.f1); { convert after read }
r.f1 := etmp;
etmp := BCDToExtended(r.f2);
r.f2 := etmp;
{ process r...}
etmp := r.f1;
r.f1 := ExtendedToBCD(etmp); { convert back before write
}
etmp := r.f2;
r.f2 := ExtendedToBCD(etmp);
write(rfile,r);
What's left
-----------
Hopefully this unit will help you with your porting efforts, it
did me! Of course there will still be issues such as Read(Kbd,...)
but that is a simple change to call ReadKey.
Support
-------
McLean Site Systems is more of a hobby than a business for me,
but I
will try and provide support, especially for those who register.
I can
not provide telephone assistance, sorry. Please email your
questions to
mcleansite@usa.net
Everyone who uses this unit is welcome to 'register' by sending
your
name and email address to mcleansite@usa.net.
Only users to include
this unit as part of a commercial for-profit product are expected
to
pay the $49.95 license fee (see ORDER.TXT and LICENSE.TXT).
Enjoy.
Randy Galbraith
McLean Site Systems