XLPack API: Delphi example programs

How to call XLPack from Delphi(Pascal)

To call XLPack from Delphi, it is necessary to use DLL directly.
DLL interface program xlpack.pas is included in SDK, so that the calling program can easily call XLPack like built-in functions without considering the detail DLL interface by declaring “uses XLPack;”.
One dimensional array is used for both coefficient matrix a and right hand matrix b.

Delphi example program (Example (1))

program test_xlpack_1;

uses XLPack;

procedure test_dgesv;
const
    n = 3; lda = n; ldb = n;
    a: array[1..n*n] of Double =
        (0.2,  -0.32, -0.8,
         -0.11, 0.81, -0.92,
         -0.93, 0.37, -0.29);
    b: array[1..n] of Double =
        (-0.3727, 0.4319, -1.4247);
var
    ipiv: array[1..n] of Integer;
    info: Integer;
begin
    Dgesv(n, lda, a, ipiv, ldb, b, info);
    Writeln('x =');
    Writeln(b[1], '  ', b[2], '  ', b[3]);
    Writeln('info = ', info);
end;

begin
    test_dgesv;
end.

Result

x =
 8.60000000000000E-0001   6.40000000000000E-0001   5.10000000000000E-0001
info = 0

Delphi example program (Example (2))

In Example (2), the integral of f(x) is computed using qk15. qk15 requires the external function defining f(x). It can be coded in Delphi and qk15 will call it when necessary.

program test_xlpack_2;

uses XLPack;

function f(x: Double): Double;
begin
    f := 1/(1 + x*x);
end;

procedure test_qk15;
var
    a, b, result, abserr: Double;
begin
    a := 0; b := 4;
    Qk15(f, a, b, result, abserr);
    Writeln('result = ', result, ', abserr = ', abserr);
end;

begin
    test_qk15;
end.

Result

result =  1.32581766136379E+0000, abserr =  1.48272394121622E-0003