请教:在TOPGrid中,我将tsdbgrid1.Cell[x,y]的值赋给一变量怎么总提示“不正确的变量类型”?(50分)

S

Silence

Unregistered / Unconfirmed
GUEST, unregistred user!
Cell的返回类型为Variant,如下:
Cell[DataCol: Longint; DataRow: Variant]: Variant;
我用如下方式赋值时总提示“不正确的变量类型”
abc:=tsdbgrid1.cell[2,5];
但反过来并不提示错误,不过也不能在grid中显示。
请问应该怎么做?
我用的是TopGrid2.2 For Delphi6版

 
要把tsdbgrid1.cell[2,5]强制转换为和abc相同的类型。
 
倒!现在又提示
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EVariantTypeCastError with message 'Could not convert variant of type (Null) into type (String)'. Process stopped. Use Step or Run to continue.
---------------------------
然后才提示
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EOleException with message '不正确的变量类型。'. Process stopped. Use Step or Run to continue.
---------------------------
我刚学delphi半个月,不懂。请大家多多指教。
 
type=null的问题已经解决了。
这个变量类型不正确的问题谁教教我啊。我可不想就此而不再学编程。[:(]
 
此类GRID.Cells[x,y]的值都是String型变量,你可以通过StrToInt,StrToFloat,StrToDateTime等涵数转换类型。

至于在Cells[x,y]遇上null时,那就在每次取值前加一个条件:
if TopGrid.Cells[x,y]<>'' then
begin
......//正确的操作
end;
或者:
While TopGrid.Cells[x,y]<>'' do
begin
......//正确的操作
end;
---------------------------------------
如果还有什么问题请及时回复
 
我用的是topgrid第三方控件,其cell[x,y]的值不是string而是Variant,按理说可以任意赋值的。
其说明为Cell[DataCol: Longint; DataRow: Variant]: Variant;
我尝试用你说的if TopGrid.Cells[x,y]<>'' then也同样提示变量类型不正确。
 
终于明白了,原来是TopGrid不支持ADO数据源。我用table可以,adotable就出错。:-(
 
查了一下官方说明,应该是可以支持的。看来还是我不会用,请高手指点。
Q13. Does TopGrid only work with BDE datasets?
No!. The TtsDbGrid will also function with any 3rd party dataset
that descends from the TDataSet primitive class. There are VERY
few (in fact I am not even sure what they are) 3rd party datasets
that do not function with TopGrid.
 
顶!总该有不少朋友用过topgrid吧?这可是大富翁里不少人推荐的。help!
 
偶就没有用过,你的DB是什么东东
 
是用adotable访问access。
 
1、关于数据不显示,请将storedata属性该True即可
2、付值方法应该正确。
 
顶部