StringGrid不能在函数中引用吗??

lxj1984 2006-07-13 12:43:53
不好意思,只有40分了...

1.为什么这样,类不能访问成员??是使用VCL的原因吗??我测试的时候,在控制台程序中写了个最简单的,只用内置类型的,就没问题
test.h:

#include <VCL.h>

class Test
{
public:
bool Query();
//.........
};

test.cpp:
#include "test.h"
//各实现代码

主界面:
#include "test.h"
//..其他include

Test t();
t.Query(); //出错?Structure required on left side of . or .*

2.我写了个函数,对StringGrid进行操作,原型如下:
void InitStringGrid( TStringGrid * grid )

结果就一个错误“expected”,看不懂,其他组件如TComboBox都可以,为什么TStringGrid会出错呢?该如何把TStringGrid用到参数中?
...全文
148 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
daydayup234 2006-07-13
  • 打赏
  • 举报
回复
第二个
注意头文件
metalwing 2006-07-13
  • 打赏
  • 举报
回复
BCB里好像累都要用new实例化的吧,所以要用t->Query()来访问其成员。
柯本 2006-07-13
  • 打赏
  • 举报
回复
第二个也没问题,可能是你程序其它地方有错,我的测试

void InitStringGrid( TStringGrid * grid )
{
grid->Cells[0][0]="Test";
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{

InitStringGrid(StringGrid1);
}
柯本 2006-07-13
  • 打赏
  • 举报
回复
第一个,明显是类的定义错:
Test t(); //要改为Test t;
t.Query(); //出错?Structure required on left side of . or .*
lxj1984 2006-07-13
  • 打赏
  • 举报
回复
谢谢,全好了
柯本 2006-07-13
  • 打赏
  • 举报
回复
daydayup234(关中刀客)说过了,要注意头文件
TStringGrid要用#include <Grids.hpp>
而TComboBox, TListBox,它在vcl.h中包了,所以不错
-------------------------------------------------------------
lxj1984 2006-07-13
  • 打赏
  • 举报
回复
谢谢,第一个本来是想调用构造函数的,现在可以了

就是第二个,我把同样的函数,写在主界面那,就可以用,但是写在其他文件里,就会出错,怎么回事呢?我不可能把所有函数都写在要用的那个文件啊

#include <VCL.h>
#include <DataModule.h>
class InfoDispose
{
public:
AnsiString QueryString;
AnsiString InsertString;
AnsiString DeleteString;

InfoDispose();

bool Query();
bool Query( AnsiString str );
AnsiString GetFirstValue( AnsiString value );
bool FillComboBox( TComboBox* combo, AnsiString value );
bool FillListBox( TListBox* list, AnsiString value );
void InitStringGrid( TStringGrid * grid );
};


这就是我才写了一点点的类了,不明白为什么前面几个同样是组件,就是StringGrid不可以
柯本 2006-07-13
  • 打赏
  • 举报
回复
to metalwing(铁翼) :
BCB只有动态类(含VCL类)才要用new实例化,BCB是ISO标准的C/C++语言,支持静态类,像:

class Test
{
int b;
public:
bool Query() {};
};


void __fastcall TForm1::Button1Click(TObject *Sender)
{
Test t;
t.Query();
}

是可以编译运行的

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧