A blob field has these methods
procedure LoadFromStream(Stream: TStream); <-- Use to update the DB
procedure SaveToStream(Stream: TStream); <-- Use to copy from the DB to
memory.
All the following is untested, but should give you workable code.
eg
To write the data from memory to the DB.
DataLocations = record
Data : array[1..6] of byte;
end;
A := TMemoryStream.Create;
try
A.WriteBuffer( DataLocations, SizeOf( DataLocations ));
//COpy the data into the stream
BlobField.LoadFromStream( A );
//Write to the DB field.
finally
A.Free;
end;
And to read from the DB into memory
A := TMemoryStream.Create;
try
BlobField.SaveToStream( A );
//Copy from the DB blob field into a stream
A.ReadBuffer( DataLocations, SizeOf( DataLocations ));
//Copy from the Stream into your record structure.
finally
A.Free;
end;
If you were to create a dervitiave of TCustomMemoryStream then you
could expose the SetPointer Method
and then you could do this instead.
A := TMemoryStream.Create;
try
A.SetPointer( @DataLocations, SizeOf( DataLocations ));
//COpy the data into the stream
BlobField.LoadFromStream( A );
//Write to the DB field.
finally
A.Free;
end;
A := TMemoryStream.Create;
try
A.SetPointer( @DataLocations, SizeOf( DataLocations ));
//This is a bit more dangerous, as sizes must be exact.
BlobField.SaveToStream( A );
//Copy from the DB blob field into a stream
finally
A.Free;
end;
And then do the
> -----Original Message-----
> From: Colin R Dillicar [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, June 07, 2000 7:27 PM
> To: Multiple recipients of list delphi
> Subject: Re: [DUG]: Streaming Data to/from BLOBs
>
>
>
> Despite a few replies to my earlier request for help I am still none the
> wiser. Most replies have steered me to the Help topics which mostly deal
> with Memo fields , certainly in respect of examples. If I understood
> exactly what was going on I wouldn't have asked and would not be
> embarrassed by asking again. I am embarrassed, I am probably rather dim -
> OK !
>
> I am having difficulty passing information between a BLOB field in a
> database and an array in memory and would appreciate it if someone
> familiar with the process would provide me with some sample code.
>
> The array I have is "Program Data", as follows :-
>
> type
> DataLocations = record
> Data : array[1..6] of byte;
> end;
>
> var
> ProgramData : array 1..200 of DataLocations;
>
>
> Even ignoring the above record definition, I have approximately 1024 bytes
> of data that I want to pass back and forth between memory and one of a
> number of Numeric (BLOB) fields in Paradox table. What I need is a clip of
> code that does that sort of thing with a brief explanation of what's going
> on. I'm sure that from then on I'll grasp the method.
>
> Any help would be greatfully appreciated.
>
> TIA
>
> Colin
>
>
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz