Archived Forum Post

Index of archived forum posts

Question:

CSV.SetCell returning error in Delphi

Aug 14 '13 at 17:20

I am creating a CSV file from a DBase file for the first time. When I try to set the SetCell parameters, I get an error saying there are not enough parameters.

If I look at the csv.SetCell in the Delphi Help Completion tool it gives the following information

function setcell: function(row: Integer; col: Integer; const content: WideString; out pVal: Integer); Integer

When I look at the function in

function SetCell(row: Integer; col: Integer; const content: WideString): Integer; safecall;

Nowhere do I see anything in the documentation about a 4th parameter. I added an integer field called "out":

csv.setcell(row,i,s,out);

That works but I'm not sure why the version I have (1.0.1.1) needs this extra variable. I had to add the same variable to the SaveFile functions as well. I have used this for quite a while to import CSV files but this is the first I am playing with exporting data to an CSV using this component. This app is created with Delphi 4.


Answer

You're using the ActiveX here with Delphi 4, which is correct.

At the COM level, all functions return HRESULT's (which is not seen by your Delphi application). Return values, such as strings, integers, etc. are always returned as an output-only argument, which w/ Chilkat is the last argument of the function -- but again, you don't see this in Delphi (or in VB6, or in most programming languages that can use ActiveX API's. You must be looking at the COM function signature.

The way it should look in Delphi is like this:

success := csv.SetCell(0,1,'red');

Where SetCell returns 1 for success or 0 for failure. At the COM function level, it looks like this:

HRESULT SetCell([in] long row, [in] long col, [in] BSTR content, [out, retval] long *pVal);


Answer

Yes I am using the ActiveX component.

Nothing I do can get it to work using the procedure as written in the example. It is working and outputting the data as requited but I have to use that fourth variable. On inspection at runtime it has a 5 digit number in it and every instance has the same number so I'm guessing it is a window flag.

This does not work: success := csv.SetCell(0,1,'red');

This does: success := csv.SetCell(0,1,'red', out);

"Success" is a 1 but "out" is 53244. If I do not add an integer field to hold that number I get an exception error.

I am migrating this application into Delphi 7 and will let you know if the same thing occurs there.