Writing Excel Addons - Xloper Definition
(Page 3 of 8 )
TVal = packed Record
Case Byte of
1: (num: Double); (* xltypeNum *)
2: (str: ^ShortString); (* xltypeStr *)
3: (bool: Word); (* xltypeBool *)
4: (err: Word); (* xltypeErr *)
5: (w: Integer); (* xltypeInt *)
6: (sref : packed record
count:word;
ref: Xlref;
end);
8: (_array : packed Record (* xltypeMulti *)
lparray: LPXLOPERArray;
rows: WORD;
columns: WORD;
End);
9: (mref : packed record // xltyperef
lpmref : lpxlmref;
idsheet : integer;
End);
End; // tval
XlOper = packed Record
val: TVal;
xltype: WORD;
dummy:array[0..5] of byte; // pads to 16 byte size
End;
lpxloper = ^xloper;
Problem with Excel calls
From Delphi the big stumbling block with add-ins is the extra parameter after the return address on the stack. This comes free with every call to Excel. I’ve never found out what it holds, but so long as you throw it away, your add-in will work fine. Add the line asm pop variable, end; after every call where variable can be any global, local or object variable that is at least 4 bytes long- integer is fine. To repeat- THIS MUST BE INCLUDED after every Excel4v call. Otherwise you are constructing a time-bomb.
Example
Eresult:= Excel4V(xlfCaller,@xres,0,[nil]);
asm pop sink; end; // Never Remove
Note that with Delphi syntax, if xres is an xloper, you can use @xres to define an lpxloper.
Next: Caution- Recalculation Alert! >>
More Windows Scripting Articles
More By David Bolton