🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.language.delphi.general
1 messages
1 total messages Started by akalb Tue, 28 Apr 2009 07:28
how can I storage a record structure in a blob field and next reading it ???
#130
Author: akalb
Date: Tue, 28 Apr 2009 07:28
90 lines
3559 bytes
create a Table with 2 fields:
ID as integer
MyBlob as Memo


define a type like this

type
  TUser = record
    Name        : string[2];
    Cognome     : string[4];
    Eta         : integer;
    DataNascita : TDateTime;
  end;


form definition like this

  TRecord2BlobForm = class(TForm)
    DBGrid1: TDBGrid;
    ADOConnection1: TADOConnection;
    DataSource1: TDataSource;
    InsertButton: TButton;
    myTable: TADOTable;
    edNOQ: TEdit;
    DBNavigator1: TDBNavigator;
    myTableID: TIntegerField;
    myTableCampoBlob: TMemoField;
    Edit_Cognome: TLabeledEdit;
    Edit_Nome: TLabeledEdit;
    Edit_Eta: TLabeledEdit;
    Edit_DataNascita: TDateTimePicker;
    Label1: TLabel;
    procedure InsertButtonClick(Sender: TObject);
    procedure myTableAfterScroll(DataSet: TDataSet);


procedure TRecord2BlobForm.myTableAfterScroll(DataSet: TDataSet);
var
  User : TUser;
  blobF : TBlobField;
  bs : TStream;
begin
  if myTable.State in [dsInsert, dsEdit] then Exit;

  if myTable.FieldByName('MyBlob').IsBlob then
  begin
    blobF := DataSet.FieldByName('MyBlob') as TBlobField;
    bs := myTable.CreateBlobStream(blobF, bmRead);
    try
      bs.Read(User,sizeof(TUser));
    finally
      bs.Free;
    end;
  end;

  Edit_Nome.Text              := User.Name;
  Edit_Cognome.Text           := User.Cognome;
  Edit_Eta.Text               := IntToStr(User.Eta);
  Edit_DataNascita.DateTime   := User.DataNascita;
end;

procedure TRecord2BlobForm.InsertButtonClick(Sender: TObject);
var
  User : TUser;
  blobF : TBlobField;
  bs : TStream;
begin
  User.Name         := Edit_Nome.Text;
  User.Cognome      := Edit_Cognome.Text;
  User.Eta          := StrToInt(Edit_Eta.Text);
  User.DataNascita  := Edit_DataNascita.DateTime;

  myTable.Insert;

  //assign the key field
  myTable.FieldByName('id').AsInteger := myTable.RecordCount;

  blobF := myTable.FieldByName('MyBlob') as TBlobField;
  bs := myTable.CreateBlobStream(blobF, bmWrite);
  try
    bs.Write(User,SizeOf(TUser));
  finally
    bs.Free;
  end;

  myTable.Post;
end;

end.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads