I'm trying to call a Delphi DLL from Excel and return a column of variant data values. I have the dll returning a single shortstring, and that appears in a cell ok. Now I am trying to return a column of variable values. It gets into my code ok, but the array in excel is all 0.
Any ideas greatly appreciated.
Here is the macro registration in Excel: =REGISTER("c:\projects\test\delphixl.dll","GetPolicyData","KDD","GetPolicyData","Co,Pol",1,"Delphi")
I'm not sure what the 1 is after the parameters; I cant find full documentation anywhere.
the range in Excel has: {=GetPolicyData(C1,D1)}
Below is the code in D7. According to the excel doc for the register functions, this appears to be OK.
K Data Type
The K data type uses a pointer to a variable-size FP structure. You must define this structure in the DLL or code resource as follows:
typedef struct _FP
{
unsigned short int rows;
unsigned short int columns;
double array[1]; /* Actually, array[rows][columns] */
} FP;
Type
pPolicyData = ^tPolicyData;
tPolicyData = Record
Rows: word;
Cols: word;
data: variant;
End;
var
pd: tPolicyData;
Function GetPolicyData(co: pShortString; pol: pShortString): pPolicyData; Stdcall;
Var
polc: tpolcmst;
Begin
lpro := tlifepro.create;
lpro.opendatabases;
polc := tpolcmst.create(lpro);
Try
polc.read(co^, pol^);
pd.Rows := 2;
pd.Cols := 1;
pd.data := VarArrayCreate([0, 1], varVariant);
pd.data[0] := datetostr(polc.issuedate);
pd.data[1] := format('%.2f', [polc.modepremium]);
result := addr(pd);
Finally
lpro.closedatabases;
freeit(lpro);
End;
End;