Invalid class typecast? 提示?

baal_zf 2002-04-27 05:41:19
在三层结构中,在服务器上用Query查询一个blob字段Record !参数ID由客户端动态传回?可是用下边程序读取Record时 提示--Invalid class typecast
请各位大虾赐教!
ClientDataSet2->Close();
ClientDataSet2->Params->ParamByName("CID")->Value=StrToInt(Edit1->Text);
ClientDataSet2->Open();
TBlobField *pField=(TBlobField *) ClientDataSet2->FieldByName("Record");
TClientBlobStream *pmem=new TClientBlobStream(pField,bmRead);
pmem->Seek(0,soFromBeginning);
TMemoryStream *ms=new TMemoryStream();
ms->LoadFromStream(pmem);
if(FileExists("\\temp.doc"))
DeleteFile("\\temp.doc");
FileCreate("\\temp.doc");
ms->SaveToFile("\\temp.doc");
pmem->Free();
ms->Free();
...全文
201 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wingsun 2002-04-27
  • 打赏
  • 举报
回复
TCustomClientDataSet::CreateBlobStream

Returns a TClientBlobStream object for reading or writing the data in a specified blob field.

virtual Classes::TStream* __fastcall CreateBlobStream(Db::TField* Field, Db::TBlobStreamMode
Mode);

Description

Call CreateBlobStream to obtain a stream for reading data from or writing data to a binary large object (BLOB) field. The Field parameter must specify a TBlobField component from the Fields property array. The Mode parameter specifies whether the stream will be used for reading, writing, or updating the contents of the field.

Note: Calling CreateBlobStream ensures that the current record has fetched its BLOB data if the FetchOnDemand property is true. If FetchOnDemand is false and the provider does not include BLOB data in data packets by default, call FetchBlobs before calling CreateBlobStream.
Wingsun 2002-04-27
  • 打赏
  • 举报
回复
我大概知道了你的问题所在你的BlobStream类错了,你用TStream试一试,帮助上是这么说的。
jishiping 2002-04-27
  • 打赏
  • 举报
回复
我怎么总觉得你写的程序总是有很多不必要的代码。
下面的代码是不是简洁多了。

ClientDataSet2->Close();
//不知道你之前的ClientDataSet2->SQL->Text的
//内容是什么,所以下面的一句无法判断对错
ClientDataSet2->Params->ParamByName("CID")
->AsInteger = strToInt(Edit1->Text);
ClientDataSet2->Open();
TBlobField *pField = (TBlobField*)ClientDataSet2
->FieldByName("Record");
pField->SaveToFile("\\temp.doc"); //最好使用全路径
jerrymousenet2 2002-04-27
  • 打赏
  • 举报
回复
TBlobField *pField=(TBlobField *) ClientDataSet2->FieldByName("Record");这一句进行类型转换时出错。
jishiping 2002-04-27
  • 打赏
  • 举报
回复
TBlobField *pField=(TBlobField *) ClientDataSet2->
FieldByName("Record"); 这一句进行类型转换时出错。
没看出有什么问题啊。是运行时的问题吗?还是编译时的错误。如果是
编译时的错误,那么这样写好了:
TBlobField *pField = dynamic_cast<TBlobField*>
ClientDataSet2->FieldByName("Record");
baal_zf 2002-04-27
  • 打赏
  • 举报
回复
TO:ouyang75928(Borland是我一生所爱)
TBlobField *pField=(TBlobField *) ClientDataSet2->FieldByName("Record");这一句进行类型转换时出错。
why?

13,825

社区成员

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

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