Contents - Index


Example .DLP External Procedure in DELPHI

 

MDAS is an acronym for 'multiply-divide-add-subtract.  MDAS takes two input values and returns four outputs which are the product, the ratio, the sum, and the difference of the two numbers.  Although the MDAS procedure itself is no use, it is shown here to illustrate how to write external procedures for EES in DELPHI.  To illustrate the unit checking capability, the units for the inputs are set to be 'm'.  The source code follows. 

 

______________________________________________________

library MDASP;

 

const Example = -1;

         InputUnits = -2;

         OutputUnits = -3;

 

type

  CharString = array[0..255] of char;

  ParamRecPtr=^ParamRec;

  ParamRec=record

    Value:double;

    next:ParamRecPtr;

  end;

 

function CountValues (P: ParamRecPtr): integer;

  var

   N: integer;

  begin

   N := 0;

   while (P <> nil) do begin

     N := N + 1;

     P := P^.next

    end;

   CountValues := N;

  end; {­CountValues}

 

procedure MDAS(var CString:CharString; var Mode:integer;

      Inputs,Outputs:ParamRecPtr); export; stdcall;

 

procedure MyDearAuntSally;

  var

    P1, P2: extended;

    P: ParamRecPtr;

  begin

    P := Inputs;

    P1 := P^.Value;

    P := P^.next;

    P2 := P^.value;

    P := Outputs;

    P^.Value := P1 * P2;

    P := P^.next;

    P^.Value := P1 / P2;

    P := P^.next;

    P^.Value := P1 + P2;

    P := P^.next;

    P^.Value := P1 - P2;

  end; {­doCall}

 

begin {­MDAS}

  if (Mode = Example) then

     CString := 'CALL MDAS(In1,In2:Out1,Out2,Out3,Out4)'

  else if (Mode=InputUnits) then

     CString := 'm,m'

  else if (Mode=OutputUnits) then

     CString := 'm^2, ,m,m'

  else begin

    if (CountValues(Inputs) <> 2) then begin

      CString := 'Wrong number of inputs for MDAS.';

      exit;

    end;

    if (CountValues(Outputs) <> 4) then begin

      CString := 'Wrong number of outputs for MDAS.';

      exit;

    end;

    MyDearAuntSally;

    CString:='';

   end;

end; {­MDAS}

 

exports

   MDAS;

 

begin

  {­no initiation code needed}

end. 

__________________________________________________________________

 

This file was compiled using DELPHI XE4.  After building, file MDASP.dll is generated.  It is necessary to rename it to MDAS.DLP.