找传奇、传世资源到传世资源站!

数据库二进制大类保存+读取

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

【例子介绍】

【相关图片】

from clipboard

【源码结构】

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, DBTables, Grids, DBGrids, Mask, DBCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Table1: TTable;
    Table1hjz: TStringField;
    Table1zq1: TStringField;
    Table1vbn: TBlobField;
    DataSource1: TDataSource;
    Panel2: TPanel;
    DBNavigator1: TDBNavigator;
    DBGrid1: TDBGrid;
    DBEdit2: TDBEdit;
    DBEdit1: TDBEdit;
    Button2: TButton;
    Button3: TButton;
    Button1: TButton;
    Panel3: TPanel;
    edit2: TMemo;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    GroupBox1: TGroupBox;
    edit1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

shuzhu=array[0..10001] of real;

var
  Form1: TForm1;
  myv,mm1:shuzhu;
  j:word;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
j:=0;
  with table1 do
  begin
    close;
    tablename:='hjz'; //创建HJZ数据库表
    if not exists then     //如果不存在
    begin
      CreateTable;         //就创建一个( tablename:='hjz'; //创建HJZ数据库表)
    end;
    open;  //  打开
  end;

  //固定屏幕大小:
  form1.Width:=978;
  form1.Height:=582;

end;

procedure TForm1.Button1Click(Sender: TObject);
var
  vj:Tblobstream;    //声明流数据变量
  sj:Tblobstream;    //声明流数据变量
  i:integer;
begin
  for i:=0 to 10000 do myv[i]:=i j;  //生成数组数据
  with table1 do
  begin
    append; //插入新数据
    table1hjz.Value:='朱庆' inttostr(j); //写数据库第一个字段
    table1zq1.Value:='zhuqng' inttostr(i); //写数据库第2个字段

    vj:=Tblobstream.Create(table1vbn,bmwrite);  //流
    vj.Write(myv,sizeof(myv));//myv=数组;sizeof(myv):数组长度大小
    vj.Free; //释放内存
    post; //更新
    //--------------------------------
    edit1.Text:=''; //清空之前的显示
    for i:=0 to 3000 do
    begin
       edit1.Text:=edit1.Text floattostr(myv[i]) '  ';
       //edit1.Lines.Add(edit1.Text floattostr(myv[i]) '  ');
    end;
  end;
   j:=j 1;
end;

procedure TForm1.Button2Click(Sender: TObject); //读取
begin
form1.Close;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  nj:Tblobstream;    //声明流数据变量
  i:integer;
begin
  with table1 do
  begin
//从数据库读取数组数据
   nj:=Tblobstream.Create(table1vbn,bmRead);  //流
   nj.Read(mm1,sizeof(mm1));
   nj.Free; //释放内存

   edit2.Text:=''; //清空之前的显示
   //显示读取数据:
   for i:=0 to 1000 do
    begin
       edit2.Text:=edit2.Text floattostr(mm1[i]) '  ';
    end;
  end;
end;

end.





评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复