Use {$ INCLUDE} or {$ I} instructions to manage and call custom functions in Delphi
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 =class (TForm) procedure FormCreate (Sender: TObject); end ; var Form1: TForm1; implementation {$ R * .dfm} // For example, the following four custom functions ***************************** function MyAdd (const a, b: Integer): Integer; begin Result: = a + b; end ; function MyDec (const a, b: Integer): Integer; begin Result: = a-b; end ; function MyMul (const a, b: Integer): Integer; begin Result: = a * b; end ; function MyDiv (const a, b: Integer): Integer; begin Result: = adiv b; end ; // ********************************************** ****** // call test procedure TForm1.FormCreate (Sender: TObject); const x =8; y = 2; begin ShowMessageFmt ('% d,% d,% d,% d', [MyAdd (x, y), MyDec (x, y), MyMul (x, y), MyDiv (x, y)]); {Display result: 10,6,16,4} end ; end .
We can cut and save the custom function (or other code) in a text file (for example: C: \ DelphiFun \ MyFun.inc);
then use {$ INCLUDE C: \ DelphiFun \ MyFun.inc} or {$ IC: \ DelphiFun \ MyFun.inc} can be imported again (relative paths can be used).
Here is the code after use:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 =class (TForm) procedure FormCreate (Sender: TObject); end ; var Form1: TForm1; implementation {$ R * .dfm} {$ IC: \ DelphiFun \ MyFun.inc} // call test procedure TForm1.FormCreate (Sender: TObject); const x =8; y = 2; begin ShowMessageFmt ('% d,% d,% d,% d', [MyAdd (x, y), MyDec (x, y), MyMul (x, y), MyDiv (x, y)]); {Display result: 10,6,16,4} end ; end .
In addition: The C language obj file is completed with the {$ L path} instruction.