Load BLOB Field From MSSQL Add to PSafeArray --->Help!

Please discuss general Delphi programming topics here.

Load BLOB Field From MSSQL Add to PSafeArray --->Help!

Postby psomkuan » September 17th, 2010, 1:25 pm

var
BS : TStream;
l_pArray : PSafeArray;
begin
FingerRec.Open; // Database Table
FingerRec.First;
While Not FingerRec.EOF Do
begin
BS := FingerRec.CreateBlobStream(FingerRec.FieldByName('f_template'), bmRead); // Blobfield = 'f_template'

.... // can't do it

FingerRec.Next;
end;
BS.Free;
FingerRec.Close;
FingerRec.Free;
end;

](*,) =D> [-o<
User avatar
psomkuan
Active Member
Active Member
 
Posts: 5
Joined: September 13th, 2010, 2:27 pm
Location: Bangkok Thailand

Re: Load BLOB Field From MSSQL Add to PSafeArray --->Help!

Postby Kambiz » September 18th, 2010, 3:58 pm

Your question is not clear! What are you going to do with the blob stream?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Load BLOB Field From MSSQL Add to PSafeArray --->Help!

Postby psomkuan » September 19th, 2010, 2:33 am

Hi Kambiz

I use fingerprint Futronic FS80 but don't have sample for Delphi.
I convert VB.NET to Delphi

Sample VB.NET Source code
//*******************************
Dim Template() As Byte
While Not UserFinRec.EOF
ReDim Template(UserFinRec("fTemplate").ActualSize)
Template = UserFinRec("fTemplate").Value
'Add finger from database to identify (1-N)
ScanerCtrl1.AddIdentifyDB(Template, UserFinRec("uName").Value)
UserFinRec.MoveNext()
End While

//*******************************
Question I can't add data from blobfield to byterec : PSafeArray in this function.

function TScanerCtrl.AddIdentifyDB(var byteRec: PSafeArray; const strKey: WideString): WordBool;
begin
Result := DefaultInterface.AddIdentifyDB(byteRec, strKey);
end;
//********************************

My Source Code

var
Name: WideString;
BlobStream: TStream;
Template : PSafeArray;

begin
Name := FingerRec.FieldByName('f_name').AsWideString;
BlobStream := FingerRec.CreateBlobStream(FingerRec.FieldByName('f_template'), bmRead);

// Convert BlobStream to Template :oops:

ScanerCtrl1.AddIdentifyDB(Template, Name);
end;

Thank , for the answer.
psomkuan.
User avatar
psomkuan
Active Member
Active Member
 
Posts: 5
Joined: September 13th, 2010, 2:27 pm
Location: Bangkok Thailand

Re: Load BLOB Field From MSSQL Add to PSafeArray --->Help!

Postby Kambiz » September 19th, 2010, 6:06 am

You should copy the blob stream in to a memory stream to have direct access to data bytes.

Code: Select all
var
  Name: WideString;
  BlobStream: TStream;
  MemStream: TMemoryStream;
  Template: PSafeArray;
begin
  Name := FingerRec.FieldByName('f_name').AsWideString;
  MemStream := TMemoryStream.Create;
  try
    BlobStream := FingerRec.CreateBlobStream(FingerRec.FieldByName('f_template'), bmRead);
    try
      MemStream.CopyFrom(BlobStream, 0);
    finally
      BlobStream.Free;
    end;
    Template := PSafeArray(MemStream.Memory);
    ScanerCtrl1.AddIdentifyDB(Template, Name);
  finally
    MemStream.Free;
  end;
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Load BLOB Field From MSSQL Add to PSafeArray --->Help!

Postby psomkuan » September 19th, 2010, 12:34 pm

Hi Kambiz

I follow at you tells , It's work, but i convert MemoryStream to OleVariant and convert back to PSafearray.

Code: Select all
var
  Name: WideString;
  BlobStream: TStream;
  MemStream: TMemoryStream;
  Template: PSafeArray;
  aVariant : OleVariant;

//*******************************
procedure StreamToVariant (Stream : TMemoryStream; var v : OleVariant);
var
  p : pointer;
begin
  v := VarArrayCreate ([0, Stream.Size - 1], varByte);
  p := VarArrayLock (v);
  Stream.Position := 0;
  Stream.Read (p^, Stream.Size);
  VarArrayUnlock (v);
end;
//*******************************

  Name := FingerRec.FieldByName('f_name').AsWideString;
  MemStream := TMemoryStream.Create;
try
    BlobStream := FingerRec.CreateBlobStream(FingerRec.FieldByName('f_template'), bmRead);
    try
      MemStream.CopyFrom(BlobStream, 0);
    finally
      BlobStream.Free;
    end;
    StreamToVariant(MemStream,aVariant);
    Template := PSafeArray(TVarData(aVariant).VArray);

//    Template := PSafeArray(MemStream.Memory);
    ScanerCtrl1.AddIdentifyDB(Template, Name);
finally
    MemStream.Free;
end;
  ScanerCtrl1.LockIdentifyDB();
end;


Thank for the assistance ,
psomkuan.
User avatar
psomkuan
Active Member
Active Member
 
Posts: 5
Joined: September 13th, 2010, 2:27 pm
Location: Bangkok Thailand

Re: Load BLOB Field From MSSQL Add to PSafeArray --->Help!

Postby Kambiz » September 19th, 2010, 5:53 pm

In this case, you do not need the memory stream. You can directly use the blob stream for creating OleVariant.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 6 guests

cron