[top] [up] [next]

Borland Delphi interface


The Trinc-Prolog DLL can be used with Borland Delphi 2 and higher. The pascal file dll\Delphi\tp_dll.pas contains the functions, procedures and a Delphi component class for using the Trinc-Prolog DLL. There are examples In the subfolders dll\delphi of using the function and component interfaces. The subfolders func and comp contain examples for Delphi 3 and higher, the subfolder delphi2 contains examples for Delphi 2.

To install the component class in the component palette the Trinc-Prolog DLL file (tp_32.dll) and the necessary files (system.txt, tcads.str, tcwin.str and pl.str) must be in the search path of the Delphi compiler. With Delphi 2 make sure to create a backup of the component library file (CMPLIB32.DLL) before installing the component. With Delphi 3 and higher the best way to install the component class is:

  1. Select from the Delphi main menu the menu item 'Component'.
  2. Choose the tab 'Into new package'.
  3. Select the file dll\delphi\'tp_dll.pas' as the 'Unit file name'.
  4. Select a new file for a package.
  5. Enter a description for the new package.
  6. Press the "OK" button and a new package will be created and the TPrologEngine component will be installed.

The Delphi function/procedure interface

It is not necessary to use the import library file tp_32.lib as with the C interface during linking of a Delphi application. The pascal file to use is tp_dll.pas and it is located in the folder dll\delphi. The function/procedure interface contains:

function DLL_TPVersion: Integer
func Return the version number of the current interface of the DLL.
pre TRUE
post The version number was returned.

function DLL_TPInit: Integer

func Initialize the Trinc-Prolog DLL. The instance handle of the DLL is used to initialize it.
pre TRUE
post If the DLL was correct initialized then was TP_TRUE returned, else a negative result  code was returned.

function DLL_TPInit( Instance: LongInt ): Integer

func Initialize the Trinc-Prolog DLL with the supplied instance handle.
pre TRUE
post If the DLL was correct initialized then was TP_TRUE returned, else a negative result  code was returned.

procedure DLL_TPExit

func Stop using the Trinc-Prolog DLL. Any still present prolog engine instances are deleted.
pre TRUE
post The DLL can no longer be used, all the allocated resources of the DLL were released.

procedure DLL_TPExit( Instance: LongInt )

func Stop using the Trinc-Prolog DLL. The same Instance handle as used for initialization is used to release the allocated resources. Any still present prolog engine instances are deleted.
pre The same instance handle must have been used for initialization.
post The DLL can no longer be used, all the allocated resources of the DLL were released.

function DLL_TPNewEngine: Integer

func Create a new prolog engine instance and initialize it.
pre The DLL must have been successfully initialized.
post The engine identifier of the new prolog engine instance was returned, if there was an error then a negative error code was returned (< 0).

procedure DLL_TPDeleteEngine( EngineId: Integer )

func Delete the engine specified by the identifier "EngineId".
pre TRUE.
post The engine with the same identification number was deleted.

function DLL_TPProve( EngineId:Integer; Goal:string ): Integer

func Have the specified goal proven by the engine identified by "EngineId".
pre The parameter "Goal" may not be NULL.
post If the goal was proven successfully and a solution was found was TP_SOLUTION returned, if the goal failed then was TP_FAIL returned, else one of the following error codes: "TPERROR_INCORRECT_GOAL", "TPERROR_UNKNOWN_ENGINE" or "TPERROR_PROVE" was returned.

function DLL_TPContinue( EngineId: Integer ): Integer

func Continue proving the current goal of the engine until the next solution.
pre A solution must have been found by a previous call to the function Prove.
post If the goal was proven successfully and a solution was found was TP_SOLUTION returned, if the goal failed then was TP_NO returned, else one of the following error codes: "TPERROR_INCORRECT_GOAL", "TPERROR_UNKNOWN_ENGINE" or "TPERROR_PROVE" was returned.

function DLL_TPNumVars( EngineId: Integer ): Integer

func Retrieve the number of variables in the last solution found by the specified engine.
pre A solution was found.
post The number of variables was returned, if the engine was not found then TPERROR_UNKNOWN_ENGINE was returned, else the number of variables was  returned.

function DLL_TPVarName( EngineId, Index: Integer ): pchar

func Get the name of the specified variable of the last solution generated by the engine identified by "EngineId".
pre A solution was found AND "Index" >= 0 AND "Index" < "NumVars".
post If the variable was found then the name of it was returned, else was NIL returned. To store the name of the variable create a copy of the returned character string.

function DLL_TPVarValue( EngineId, Index: Integer ): pchar

func Get the value of the specified variable of the last solution generated by the engine identified by "EngineId".
pre A solution was found AND "Index" >= 0 AND "Index" < "NumVars".
post If the variable was found then the value was returned, else was NIL returned. To store the value of the variable create a copy of the returned character string.

function DLL_TPVarType( EngineId, Index: Integer ): Integer

func Get the type of the value of the specified variable of the last solution generated by the engine identified by "EngineId".
pre A solution was found AND "Index" >= 0 AND "Index" < "NumVars".
post If the variable was found then the type of the value was returned, else was TPTYPE_UNKNOWN returned. The following type constants are defined:
    TPTYPE_UNKNOWN = No value or unknown type.
    TPTYPE_EMPTYLIST = An empty list.
    TPTYPE_LIST = A list with elements.
    TPTYPE_EMPTY = An empty variable.
    TPTYPE_INTEGER = An integer number value.
    TPTYPE_FLOAT = A floating point value.
    TPTYPE_STRUCTURE = A structure value.
    TPTYPE_ATOM = An atom value.

procedure DLL_TPPutDLLSettings( AppName, AppVersion, AppHelpFile, AppCopyright, AppCompanyName: string )

func Set the name, version, help file name, copyright message and company name of the application. These values are displayed if the user, for instance opens the About dialog from inside a TPWin application being interpreted by the Trinc-Prolog DLL.
pre Any of the parameters may be NIL.
post The supplied values were stored.
remark There is another version of this procedure that uses the pchar type instead of the string type for the parameters, this version of the function is called DLL_TPPutSettings.

The Delphi Component class

The Delphi component class encapsulates the function/procedure interface. Using the component class makes a program simpler, the class takes care of initializing, exiting the DLL and instances of the component class store the engine identifier of a prolog engine instance as a private attribute. The component class is called TPrologEngine and it is located in the file dll\delphi\tp_dll.pas. The declaration of the component class is:

TPrologEngine
    Create( AOwner:TComponent )
func Constructor.
pre TRUE
post The DLL will be loaded if the first instance of the class is created.
Destroy
func Virtual destructor.
pre TRUE
post The instance was deleted, if the last instance is deleted the DLL will be unloaded.
function ProveGoal( Goal:string ): Integer
func Prove the goal.
pre A goal to prove must have been supplied.
post If the goal was proven successfully and a solution was found was TP_SOLUTION returned, if the goal failed then was TP_FAIL returned, else one of the following error codes: "TPERROR_INCORRECT_GOAL", "TPERROR_UNKNOWN_ENGINE" or "TPERROR_PROVE" was returned.
function Continue: Integer
func Find the next solution.
pre A solution must have been found by a previous call to the method ProveGoal.
post If the goal was proven successfully and a solution was found was TP_SOLUTION returned, if the goal failed then was TP_NO returned, else one of the following error codes: "TPERROR_INCORRECT_GOAL", "TPERROR_UNKNOWN_ENGINE" or "TPERROR_PROVE" was returned.
function NumVars: Integer
func Return the number of variables in the last solution.
pre A solution was found.
post The number of variables was returned.
function VarName( Index:Integer ): string
func Return the name of a specific variable from the last solution.
pre A solution was found AND "Index" >= 0 AND "Index" < "NumVars".
post The name of the variable was returned.
function VarValue( Index: Integer ): string
func Return the value of a specific variable from the last solution.
pre A solution was found AND "Index" >= 0 AND "Index" < "NumVars".
post A string representation of the value was returned.
function VarType( Index:Integer ): Integer
func Return the type of the value of a specific variable from the last solution.
pre A solution was found AND "Index" >= 0 AND "Index" < "NumVars".
post One of the following values will be returned:
    TPTYPE_UNKNOWN
    TPTYPE_EMPTYLIST
    TPTYPE_LIST
    TPTYPE_EMPTY
    TPTYPE_INTEGER
    TPTYPE_FLOAT
    TPTYPE_STRUCTURE
    TPTYPE_ATOM

In Delphi it is possible to add the component class to the component palette but it is necessary that the DLL file (tp_32.dll) and the pascal file (tp_dll.pas) are in the search path of the Delphi compiler while the component palette is being re-build. With Delphi 2 it is very important to create a backup of the file cmplib32.dll before the component is added.

[top] [up] [next]

 

info@trinc-prolog.com