home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / turbo55 / install / demos.arc / CPASDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1989-05-02  |  4KB  |  126 lines

  1.  
  2. { Copyright (c) 1985, 1989 by Borland International, Inc. }
  3.  
  4. program CPASDEMO;
  5. (*
  6.   This program demonstrates how to interface Turbo Pascal and Turbo C.
  7.   Turbo C is used to generate an .OBJ file (CPASDEMO.OBJ). Then
  8.   this .OBJ is linked into this Turbo Pascal program using the {$L}
  9.   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
  25.        them using CTOPAS.BAT.  If you do recompile them, make sure
  26.        that you include prototypes in your C module for all C
  27.        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 the following
  34.   files:
  35.  
  36.     TCC.EXE and TURBO.CFG or
  37.     TC.EXE and CTOPAS.TC
  38.  
  39.   To run the demonstration program CPASDEMO.EXE do the following:
  40.  
  41.   1. First create a CPASDEMO.OBJ file compatible with Turbo Pascal 5.5
  42.      using Turbo C.
  43.  
  44.     a) If you are using the Turbo C integrated environment (TC.EXE)
  45.        then at the DOS prompt execute:
  46.  
  47.        TC /CCTOPAS.TC CPASDEMO.C
  48.  
  49.        then create the .OBJ file by pressing ALT-F9.
  50.  
  51.     b) If you are using the Turbo C command line version (TCC.EXE)
  52.        then at the DOS prompt execute:
  53.  
  54.        TCC CPASDEMO.C
  55.  
  56.        Note: Use the same configuration file (TURBO.CFG or CTOPAS.TC)
  57.              when you create your own Turbo C modules for use with
  58.              Turbo Pascal 5.5
  59.  
  60.   2. Compile and execute the Turbo Pascal program CPASDEMO.PAS
  61.  
  62.   This simple program calls each of the functions defined in the Turbo C
  63.   module. Each of the Turbo C functions changes the current display color
  64.   by calling the Turbo Pascal procedure SetColor.
  65. *)
  66.  
  67. uses Crt;
  68.  
  69. var
  70.   Factor : Word;
  71.  
  72. {$L CPASDEMO.OBJ}  { link in the Turbo C-generated .OBJ module }
  73.  
  74. function Sqr(I : Integer) : Word; external;
  75. { Change the text color and return the square of I }
  76.  
  77. function HiBits(W : Word) : Word; external;
  78. { Change the text color and return the high byte of W }
  79.  
  80. function Suc(B : Byte) : Byte; external;
  81. { Change the text color and return B + 1 }
  82.  
  83. function Upr(C : Char) : Char; external;
  84. { Change the text color and return the upper case of C }
  85.  
  86. function Prd(S : ShortInt) : ShortInt; external;
  87. { Change the text color and return S - 1 }
  88.  
  89. function LoBits(L : LongInt) : LongInt; external;
  90. { Change the text color and return the low word of L }
  91.  
  92. procedure StrUpr(var S : string); external;
  93. { Change the text color and return the upper case of S - Note that the Turbo }
  94. { C routine must skip the length byte of the string.                         }
  95.  
  96. function BoolNot(B : Boolean) : Boolean; external;
  97. { Change the text color and return NOT B }
  98.  
  99. function MultByFactor(W : Word) : Word; external;
  100. { Change the text color and return W * Factor - note Turbo C's access of }
  101. { Turbo Pascal's global variable.                                        }
  102.  
  103. procedure SetColor(NewColor : Byte); { A procedure that changes the current }
  104. begin                                { display color by changing the CRT    }
  105.   TextAttr := NewColor;              { variable TextAttr                    }
  106. end; { SetColor }
  107.  
  108. var
  109.   S : string;
  110.  
  111. begin
  112.   Writeln(Sqr(10));                  { Call each of the functions defined   }
  113.   Writeln(HiBits(30000));            { passing it the appropriate info.     }
  114.   Writeln(Suc(200));
  115.   Writeln(Upr('x'));
  116.   Writeln(Prd(-100));
  117.   Writeln(LoBits(100000));
  118.   S := 'abcdefg';
  119.   StrUpr(S);
  120.   Writeln(S);
  121.   Writeln(BoolNot(False));
  122.   Factor := 100;
  123.   Writeln(MultbyFactor(10));
  124.   SetColor(LightGray);
  125. end.
  126.