将数据库图片显示出来的一个小问题。
我在一个程序里有一小段是要将数据库中的一幅图片显示在Image2里,我编写了如下程序,可为什么在执行时总提示我这个错误呢:
[C++ Error] Newsearch1.cpp(183): E2288 Pointer to structure required on left side of -> or -> *
代码程序:
TMemoryStream*pms1=new TMemoryStream();
Table1-> FieldValues[ "Picture "]-> SaveToStream(pms1); <-------这是第183行
pms1-> Position=0;
Image2-> Picture-> Bitmap-> LoadFromStream(pms1);
Label2-> Caption=Table1-> FieldValues[ "Name "];
delete pms1;
谢谢回答,我应该怎么改呢?
[解决办法]
Table1-> FieldValues[ "Picture "]-> SaveToStream(pms1); 这当然有问题了
Table1-> FieldValues[ "Picture "]是Variant 类型的,怎么能有SaveToStream方法呢?
只有TBlobField类型才有这个方法.
[解决办法]
具体参考BCB的例子:
Saves the contents of the BLOB field to a stream.
void __fastcall SaveToStream(Classes::TStream* Stream);
Description
Use SaveToStream to copy the contents of a BLOB field to a stream. Specify the name of the stream to which the field抯 value is saved as the value of the Stream parameter.
Note:The Stream parameter is typically not a BLOB stream. BLOB streams (returned by the dataset抯 CreateBlobStream method) provide a completely separate mechanism for streaming data from a BLOB field.
TMemoryStream *pMS = new TMemoryStream;
try
{
SQLDataSet1Images-> SaveToStream(pMS);
Image1-> Picture-> Bitmap-> LoadFromStream(pMS);
}
__finally
{
delete pMS;
}
[解决办法]
//读
TBlobField * pField=(TBlobField *)pQuery-> FieldByName( "Image ");
TADOBlobStream* pmem=new TADOBlobStream (pField,bmRead);
pmem-> Seek(0,soFromBeginning);
Graphics::TBitmap * pBitmap=new Graphics::TBitmap();
pBitmap-> LoadFromStream(pmem);
Image1-> Picture-> Assign(pBitmap);
delete pBitmap;
delete pmem;
//写
pQuery-> Edit();
TBlobField * pField=(TBlobField *)pQuery-> FieldByName( "Image ");
TADOBlobStream * pmem=new TADOBlobStream (pField,bmWrite);
pmem-> Seek(0,soFromBeginning);
Graphics::TBitmap * pBitmap=new Graphics::TBitmap();
pBitmap-> Assign(Image1-> Picture-> Graphic);
pBitmap-> SaveToStream(pmem);
delete pBitmap;
delete pmem;
pQuery-> Post();
[解决办法]
TTable 也一样.
例如:你的那个字段是Images,表是Table1.
那么就是
TMemoryStream *pMS = new TMemoryStream;
try
{
Table1Images-> SaveToStream(pMS);
Image1-> Picture-> Bitmap-> LoadFromStream(pMS);
}
__finally
{
delete pMS;
}
[解决办法]
我用的数据库是Table,不是Query。
================================
将Query换成你的Table
将TADOBlobStream 换成TBlobStream试试