Excel类型库/ Delphi 2009 /错误的变量类型 [英] Excel type library / Delphi 2009/ bad variable type

查看:108
本文介绍了Excel类型库/ Delphi 2009 /错误的变量类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们刚刚将一个使用Excel类型库的应用程序从Delphi 2006更新到了Delphi2009。我发现现在几乎没有任何效果-几乎所有对Excel的调用都会导致消息错误的变量类型。例如,我们可以这样做:Sheet.Cells.Item [Row,Column] .Value:= Value其中Sheet是ExcelWorksheet,而Value是Variant。我们在堆栈中看到的第二件事是在Variants中调用_DispInvoke,然后调用ComObj。我在做什么错了?

We have just updated an application which uses the Excel type library to Delphi 2009 from Delphi 2006. What I am finding is that nearly nothing now works - nearly any call to Excel results in a message "Bad variable type.". For example we may do: Sheet.Cells.Item[Row, Column].Value := Value where Sheet is an ExcelWorksheet and Value is a Variant. The next thing we see in the stack is a call to _DispInvoke in Variants, and then on into ComObj. What am I doing wrong?

推荐答案

事实证明,我们有一个通用过程来设置单元格形式的值:

It turned out that we had a generic procedure to set value of a cell of the form:

procedure SetValue(aSheet: ExcelWorksheet; aRow, aCol: Integer; aValue: Variant)
begin
  aSheet.Cells.Item[aRow, aCol].Value := aValue;
end;

此操作因我提到的错误而失败。如果我将其更改为:

this fails with the error I mentioned. If I change this to:

procedure SetValue(aSheet: ExcelWorksheet; aRow, aCol: Integer; aValue: Variant)
var
  sValue: WideString;
begin
  sValue:= aValue;
  aSheet.Cells.Item[aRow, aCol].Value := sValue;
end;

对我来说,这表明Delphi 2009在变体方面做的有所不同(至少比D2006有所不同),除非有人有更好的解释,否则COM不会喜欢它?无论如何,我很高兴暂时对此解决方案感到困惑。

To me this suggests that Delphi 2009 is doing something different with variants (than D2006 was at least), something that COM doesn't like, unless someone has a better explanation? Anyway I'm happy to muddle on with this workaround for the time being.

这篇关于Excel类型库/ Delphi 2009 /错误的变量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆