在 C++ 中使用带有 BLOB 字段的图像和数据建设者
我是一名 C++ 程序员,使用 Borland 的 C++ Builder 5。我正在开发数据库应用程序 它现在让我感到非常悲伤...
我正在使用带有 C++ Builder 的 Paradox 7.0 表,但我根本找不到将数据插入 BLOB 的方法。 我也无法使用 TDBImage VCL 组件保存或查看图片。我最近失败的尝试是尝试 使用看似铁定的代码将图像保存到 BLOB 字段。
//-----------------------------------------
Table1->Edit();
Open->Execute();
String file=Open->FileName;
ShowMessage(file);
TBlobField *blob; blob=new (TBlobField);
blob->FieldName="Image";
blob->LoadFromFile(file);
Table1->Post();
//-----------------------------------------
编译此代码失败,发现 BlobField 没有动态对象分配函数或其他功能。
我也无法为 OLE2 组件添加 OCX 控制器,也无法将其保存在自己的 BLOB 字段中。
请任何人来帮助我
:'(
I'm a C++ programmer using Borland's C++ Builder 5. I'm working on a database application
and its causing me serious grief right now...
I'm using a Paradox 7.0 table with the C++ Builder and I simply can't find a way to insert data into BLOBs.
I also can't save or view pictures using the TDBImage VCL component either.My latest foiled attempt was trying to
save an image to a BLOB field using what seems to be an iron-clad piece of code.
//-----------------------------------------
Table1->Edit();
Open->Execute();
String file=Open->FileName;
ShowMessage(file);
TBlobField *blob; blob=new (TBlobField);
blob->FieldName="Image";
blob->LoadFromFile(file);
Table1->Post();
//-----------------------------------------
On compiling this code failed, siting that the BlobField doesn't have the dynamic object allocation function or something.
I'm also unable to add an OCX contoller for an OLE2 component nor save it in its own BLOB field.
Please, anyone, come to my aid
:'(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我印象深刻的一件事是你的台词:
首先,我不确定为什么你会使用该语法而不是:
其次,TBlobField构造函数采用一个参数,一个指向TComponent的指针,它充当对象的所有者,并且是负责之后清除内存的对象。您可以尝试的一件事是这样做:
虽然我必须承认我没有在 C++ Builder 中进行太多数据库编程,但是,上面的方法应该可以工作。
编辑:还有一件事,您使用
TBlobField
的方式永远不会与表关联。您可能会发现 about.com 上的这篇文章很有趣:在 BLOB 字段中存储记录数据[1]。它是用 Delphi 编写的,但由于 VCL 框架,应该很容易移植到 C++。您可以尝试使用以下内容,但它尚未经过测试,因此您可能会遇到一些问题,如果是这样请告诉我:
[1] http://delphi.about.com/od/database/a/record2blob.htm
One thing that struck me, was your line:
First of all, I'm not sure why you would use that syntax instead of:
Secondly the TBlobField constructor take one argument, a pointer to a TComponent, which acts as the owner for the object, and is the object responsible for clearing the memory afterwards. One thing you could try is to do this:
I must admit though that I haven't done too much database programming in C++ Builder, however, the above should work.
Edit: One more thing though, the way you use
TBlobField
is never associated with the table. You might find this article from about.com intersting: Storing Record Data in a BLOB Field [1]. It is written in Delphi, but should be easily ported to C++, due to the VCL framework.You might try to use the following instead, it is not tested though, so you might encounter some problems in doing so, if so please tell me:
[1] http://delphi.about.com/od/database/a/record2blob.htm
在Delphi中有一个名为TDataSet.CreateBlobStream的函数。由于 Delphi 7 中的一些问题,我不得不对完全相同的应用程序采取这条路线,将图像存储在悖论 blob 字段中。
有关详细信息,请参阅此链接(不幸的是 Delphi):
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/DB_TDataSet_CreateBlobStream.html
In Delphi there is a function called TDataSet.CreateBlobStream. Due to some issues way back in Delphi 7 I had to take this route for exactly the same application, storing images in a paradox blob field.
See this link for more info (unfortunately Delphi):
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/DB_TDataSet_CreateBlobStream.html