J
Jams
Unregistered / Unconfirmed
GUEST, unregistred user!
本人有如下程序,目的是实现:
Ole ===> Stream ===> TBlobField
和 TBlobField ===> Stream ===> Ole
已知:已建立了数据库表,且各字段固定,并用字段编辑器建立了永久字段,
问各路高手,如何改写程序部分以期实现上述目的,最好能够将每一步或语句
说明其目的和作用,越详细越好,多谢!!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, StdCtrls, OleCtnrs, DBCtrls, Grids, DBGrids, DBTables, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
OleContainer1: TOleContainer;
Table1IntegerField: TIntegerField;
Table1StringField: TStringField;
Table1StringField2: TStringField;
Table1StringField3: TStringField;
Table1StringField4: TStringField;
Table1StringField5: TStringField;
Table1BlobField: TBlobField;
Table1StringField6: TStringField;
Table1StringField7: TStringField;
Table1FloatField: TFloatField;
Table1BlobField2: TBlobField;
Table1BooleanField: TBooleanField;
Table1GraphicField: TGraphicField;
OleContainer2: TOleContainer;
OkBtn: TButton;
ClosBtn: TButton;
procedure OkBtnClick(Sender: TObject);
procedure ClosBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BlobStream: TBlobStream;
OleStream: TMemoryStream;
implementation
{$R *.DFM}
procedure TForm1.OkBtnClick(Sender: TObject);
Var
i: Integer;
begin
OleStream := TMemoryStream.Create;
BlobStream := TBlobStream.Create(TBlobField(Table1.Fields[6]),
bmRead); {*使用bmWrite、bmReadWrite, Delphi报错
不知何故?*}
With Table1 do
Begin
DisableControls;
Active := True;
Open;
Edit;
First;
i := 0;
While i<=1 Do {*仅使用一条记录*}
Begin
OleContainer1.SaveToStream(OleStream); {*Ole ---> TMemoryStream*}
TBlobField(FieldByname('题目内容')).LoadFromStream(OleStream);
{*将Ole的数据填入字段*}
post;
Inc(i);
Next;
end;
Close;
Open;
i := 0;
While i<=1 Do
Begin
TBlobField(FieldByname('题目内容')).SaveToStream(OleStream);
{*取字段的内容,以验证写入的正确性*}
OleContainer2.LoadFromStream(Olestream);
{*将字段填入Ole中*}
Inc(i);
Next;
end;
Close;
EnableControls;
end;
BlobStream.Free;
OleStream.Free;
end;
procedure TForm1.ClosBtnClick(Sender: TObject);
begin
Close;
end;
end.
Ole ===> Stream ===> TBlobField
和 TBlobField ===> Stream ===> Ole
已知:已建立了数据库表,且各字段固定,并用字段编辑器建立了永久字段,
问各路高手,如何改写程序部分以期实现上述目的,最好能够将每一步或语句
说明其目的和作用,越详细越好,多谢!!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, StdCtrls, OleCtnrs, DBCtrls, Grids, DBGrids, DBTables, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
OleContainer1: TOleContainer;
Table1IntegerField: TIntegerField;
Table1StringField: TStringField;
Table1StringField2: TStringField;
Table1StringField3: TStringField;
Table1StringField4: TStringField;
Table1StringField5: TStringField;
Table1BlobField: TBlobField;
Table1StringField6: TStringField;
Table1StringField7: TStringField;
Table1FloatField: TFloatField;
Table1BlobField2: TBlobField;
Table1BooleanField: TBooleanField;
Table1GraphicField: TGraphicField;
OleContainer2: TOleContainer;
OkBtn: TButton;
ClosBtn: TButton;
procedure OkBtnClick(Sender: TObject);
procedure ClosBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BlobStream: TBlobStream;
OleStream: TMemoryStream;
implementation
{$R *.DFM}
procedure TForm1.OkBtnClick(Sender: TObject);
Var
i: Integer;
begin
OleStream := TMemoryStream.Create;
BlobStream := TBlobStream.Create(TBlobField(Table1.Fields[6]),
bmRead); {*使用bmWrite、bmReadWrite, Delphi报错
不知何故?*}
With Table1 do
Begin
DisableControls;
Active := True;
Open;
Edit;
First;
i := 0;
While i<=1 Do {*仅使用一条记录*}
Begin
OleContainer1.SaveToStream(OleStream); {*Ole ---> TMemoryStream*}
TBlobField(FieldByname('题目内容')).LoadFromStream(OleStream);
{*将Ole的数据填入字段*}
post;
Inc(i);
Next;
end;
Close;
Open;
i := 0;
While i<=1 Do
Begin
TBlobField(FieldByname('题目内容')).SaveToStream(OleStream);
{*取字段的内容,以验证写入的正确性*}
OleContainer2.LoadFromStream(Olestream);
{*将字段填入Ole中*}
Inc(i);
Next;
end;
Close;
EnableControls;
end;
BlobStream.Free;
OleStream.Free;
end;
procedure TForm1.ClosBtnClick(Sender: TObject);
begin
Close;
end;
end.