How to use a blob field to hold a record structure (Views: 711)
Problem/Question/Abstract: I want to use a blob field to hold a record structure. ErrsTblErrs_Data has a blobType of "ftBlob" type LogiRec = record LOGI_REG_NUM: array[1..9] of Char; LOGI_ENT_DATE: array[1..10] of Char; LOGI_Batch_num: array[1..6] of Char; LOGI_Trac_num: array[1..6] of Char; {...} end; var Buffer: array[0..600] of char; Logi: LogiRec absolute Buffer; {...} {This works to get the data in} ErrsTblErrs_Data.asstring := Buffer; {This doesn't works to get the data out} Buffer := ErrsTblErrs_Data.asstring; Is there a more elegant way of doing this? Answer: Try something like this to record the data: var b: TBlobStream; begin Table1.Append; b := TBlobStream.Create(Table1MyBlobField, bmWrite); try b.Write(MyRecord, sizeof(MyRecord)); finally b.Free; end; Table1.Post; end; To read back: var b: TBlobStream; begin Table1.First; repeat begin b := TBlobStream.Create(Table1MyBlobField, bmRead); try b.seek(0, 0); b.Read(MyRecord, sizeof(MyRecord)); finally b.Free; end; end; until Table1.EOF; end; |