home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l044 / 4.ddi / DEMOS.ZIP / CPASDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-10-23  |  4.2 KB  |  116 lines

  1.  
  2. { Copyright (c) 1985,90 by Borland International, Inc. }
  3.  
  4. program CPASDEMO;
  5. (*
  6.   This program demonstrates how to interface Turbo Pascal and Turbo C++
  7.   (or Turbo C). Turbo C++'s command-line compiler, TCC.EXE, can be used to
  8.   generate an .OBJ file (CPASDEMO.OBJ). The .OBJ file can then linked into
  9.   this Turbo Pascal program using the {$L} compiler directive.
  10.  
  11.   NOTES:
  12.     1. Data declared in the Turbo C++ module cannot be accessed from
  13.        the Turbo Pascal program. Shared data must be declared in
  14.        Pascal.
  15.  
  16.     2. If the C++ functions are only used in the implementation section
  17.        of a unit, declare them NEAR.  If they are declared in the
  18.        interface section of a unit, declare them FAR.  Always compile
  19.        the Turbo C++ modules using the small memory model.
  20.  
  21.     3. Turbo C++ runtime library routines cannot be used because their
  22.        modules do not have the correct segment names.  However, if you have
  23.        the Turbo C++ runtime library source (available from Borland),
  24.        you can use individual library modules by recompiling them using
  25.        the TURBOC.CFG configuration file provided. If you do recompile
  26.        them, make sure that you include prototypes in your C++ module
  27.        for all C++ library functions that you use.
  28.  
  29.     4. Some of the code that Turbo C++ generates are calls to internal
  30.        routines. These cannot be used without recompiling the relevant
  31.        parts of the Turbo C++ runtime library source code.
  32.  
  33.   In order to run this demonstration program you will need all the
  34.   files required to build a Turbo C++ (or Turbo C) and the TURBOC.CFG
  35.   configuration file provided with the Turbo Pascal 6.0 distribution
  36.   diskettes.
  37.  
  38.   To build and run the CPASDEMO progarm, do the following:
  39.  
  40.   1. First create a CPASDEMO.OBJ file compatible with Turbo Pascal 6.0
  41.      using Turbo C++ (or Turbo C) by typing the following at the DOS
  42.      prompt:
  43.  
  44.          TCC CPASDEMO.C
  45.  
  46.        Make sure you use the TURBOC.CFG configuration file provided
  47.        on the Turbo Pascal distribution diskettes (in \TP\DEMOS)
  48.        when you create the .OBJ file using TCC.
  49.  
  50.   2. Compile and execute the Turbo Pascal program CPASDEMO.PAS
  51.  
  52.   This simple program calls each of the functions defined in the Turbo C++
  53.   module. Each of the Turbo C++ functions changes the current display color
  54.   by calling the Turbo Pascal procedure SetColor.
  55. *)
  56.  
  57. uses Crt;
  58.  
  59. var
  60.   Factor : Word;
  61.  
  62. {$L CPASDEMO.OBJ}  { link in the Turbo C++ .OBJ module }
  63.  
  64. function Sqr(I : Integer) : Word; external;
  65. { Change the text color and return the square of I }
  66.  
  67. function HiBits(W : Word) : Word; external;
  68. { Change the text color and return the high byte of W }
  69.  
  70. function Suc(B : Byte) : Byte; external;
  71. { Change the text color and return B + 1 }
  72.  
  73. function Upr(C : Char) : Char; external;
  74. { Change the text color and return the upper case of C }
  75.  
  76. function Prd(S : ShortInt) : ShortInt; external;
  77. { Change the text color and return S - 1 }
  78.  
  79. function LoBits(L : LongInt) : LongInt; external;
  80. { Change the text color and return the low word of L }
  81.  
  82. procedure StrUpr(var S : string); external;
  83. { Change the text color and return the upper case of S - Note that the Turbo }
  84. { C++ routine must skip the length byte of the string.                       }
  85.  
  86. function BoolNot(B : Boolean) : Boolean; external;
  87. { Change the text color and return NOT B }
  88.  
  89. function MultByFactor(W : Word) : Word; external;
  90. { Change the text color and return W * Factor - note Turbo C++'s access of }
  91. { Turbo Pascal's global variable.                                          }
  92.  
  93. procedure SetColor(NewColor : Byte); { A procedure that changes the current }
  94. begin                                { display color by changing the CRT    }
  95.   TextAttr := NewColor;              { variable TextAttr                    }
  96. end; { SetColor }
  97.  
  98. var
  99.   S : string;
  100.  
  101. begin
  102.   Writeln(Sqr(10));                  { Call each of the functions defined   }
  103.   Writeln(HiBits(30000));            { passing it the appropriate info.     }
  104.   Writeln(Suc(200));
  105.   Writeln(Upr('x'));
  106.   Writeln(Prd(-100));
  107.   Writeln(LoBits(100000));
  108.   S := 'abcdefg';
  109.   StrUpr(S);
  110.   Writeln(S);
  111.   Writeln(BoolNot(False));
  112.   Factor := 100;
  113.   Writeln(MultbyFactor(10));
  114.   SetColor(LightGray);
  115. end.
  116.