Examples Delphi

const DBConnection = 'Provider=SQLOLEDB; Initial Catalog=CMDBDraft4; Data Source=w2ks-lap-ghw';
const DBUsername = 'Draft4User';
const DBPassword = '1';
procedure TForm1.BitBtn1Click(Sender: TObject);
var ms:TMemoryStream;
bm:TBitmap;
i,j:integer;
rset:_recordSet;
v:OleVariant;
l:byte;
begin
bm:=TBitmap.create;
try
rset:=getRecSet;
if rset.eof then
raise exception.create('Empty recordset returned from GetAllEntitiesTypes');
rset.moveNext;
v:=rset.fields['icon'].value;
if varType(v)<>varArray + varByte then
raise exception.create('Data from middle tier is not an array of bytes');
if vararraydimcount(v)<>1 then
raise exception.create('Can only work with single dimensioned arrays');
ms:=TMemoryStream.Create;
try
ms.setSize(varArrayHighBound(v,1));
for i:=varArrayLowBound(v,1) to varArrayHighBound(v,1) do
begin
l:=v[i];
ms.write(l,1);
end;
ms.position:=0;
if ms.Size=0 then
raise exception.create('shit');
bm.loadfromstream(ms);
image1.picture:=TPicture(bm);
finally
ms.free;
end;
finally
bm.free;
end;
end;
function TForm1.getRecset:_RecordSet;
var
adoCon : _Connection;
adoRec : _Recordset;
begin
adoCon := CoConnection.Create();
try
adoCon.Open( DBConnection, DBUsername, DBPassword, 0 );
try
adoRec := CoRecordset.Create();
try
adoRec.CursorType := adOpenForwardOnly;
adoRec.CursorLocation := adUseClient;
adoRec.Open('SELECT * from results',adoCon,adOpenForwardOnly,adLockPessimistic,0);
try
adoRec.Set_ActiveConnection(nil);
Result := adoRec;
except
raise;
end;
finally
adoRec := nil;
end;
finally
adoCon.Close;
end;
finally
adoCon := nil;
end;
end;