3
Based on the code below, where I can retrieve the results from ADODB.Command?
This union will always work with stored Procedure, and the types of parameters that will be used are of the input and output.
unit uadolibrary;
interface
uses
ComObj, Variants;
function ADOStart(strConexao: AnsiString): Boolean;
function ADOStop: Boolean;
function ADOConfigParams(ParamName: string; ParamType, ParamIO,
ParamSize: integer; Val: variant; CanClear: Boolean = False): Boolean;
function ADOSetParamVal(ParamName: string; val: variant): Boolean;
function ADOGetParamVal(ParamName: string): Variant;
function ADOGetValue(_Indece: integer): Variant;
function ADOExecute(procname: string): Boolean;
const
{Param Data Types}
adInteger = 3;
adSingle = 4;
adDate = 7;
adBoolean = 11;
//adTinyInt = 16;
adVarBites = 16;
adUnsignedTinyInt = 17;
adDateTime = 135;
advarChar = 200;
{Param Directions}
adParamInput = 1;
adParamOutput = 2;
adParamReturnValue = 4;
{Command Types}
adCmdText = 1;
adCmdTable = 2;
adCmdStoredProc = 4;
adCmdTableDirect = 512;
adCmdFile = 256;
implementation
var
ADODBConnection,
ADORecordSet,
ADOCommand: Variant;
function ADOStart(strConexao: AnsiString): Boolean;
begin
try
ADODBConnection:= CreateOleObject('ADODB.Connection');
ADODBConnection.ConnectionString:= strConexao;
ADODBConnection.Open;
ADORecordSet:= CreateOLEObject('ADODB.Recordset');
ADOCommand:= CreateOLEObject('ADODB.Command');
ADOCommand.ActiveConnection:= ADODBConnection;
ADOCommand.CommandText:= 'Procedure';
ADOCommand.CommandType:= adCmdStoredProc;
Result:= True;
except
begin
if not (VarIsEmpty(ADODBConnection)) then
begin
ADODBConnection.Close;
ADODBConnection:= Unassigned;
end;
if not (VarIsEmpty(ADOCommand)) then
ADOCommand:= Unassigned;
if not (VarIsEmpty(ADORecordSet)) then
ADORecordSet:= Unassigned;
Result:= False;
end;
end;
end;
function ADOStop: Boolean;
begin
try
if not (VarIsEmpty(ADODBConnection)) then
ADODBConnection.Close;
ADODBConnection:= Unassigned;
ADORecordSet:= Unassigned;
ADOCommand:= Unassigned;
Result:= True;
except
Result:= False;
end;
end;
function ADOConfigParams(ParamName: string; ParamType, ParamIO,
ParamSize: integer; Val: variant; CanClear: Boolean): Boolean;
var
_W: integer;
DerivedParamSize: integer;
begin
try
case ParamType of
adInteger: DerivedParamSize:= 4;
adSingle : DerivedParamSize:= 4;
adDate : DerivedParamSize:= 8;
adBoolean: DerivedParamSize:= 1;
adVarBites: DerivedParamSize:= 1;
adUnsignedTinyInt: DerivedParamSize:= 1;
adDateTime: DerivedParamSize:= 8;
advarChar: DerivedParamSize:= ParamSize;
end;
if CanClear then
for _W:= 0 to (ADOCommand.parameters.count) - 1 do
ADOCommand.parameters.delete(0);
ADOCommand.parameters.append(
ADOCommand.createparameter(ParamName, ParamType, ParamIO,
DerivedParamSize, Val));
Result:= True;
except
Result:= False;
end;
end;
function ADOSetParamVal(ParamName: string; val: variant): Boolean;
begin
try
ADOCommand.Parameters[ParamName].Value := val;
Result:= True;
except
Result:= False;
end;
end;
function ADOGetParamVal(ParamName: string): Variant;
begin
try
Result:= ADOCommand.Parameters[ParamName].Value;
except
Result:= varEmpty;
end;
end;
function ADOExecute(procname: string): Boolean;
begin
try
ADOCommand.CommandText:= procname;
ADOCommand.CommandType:= adCmdStoredProc;
ADORecordSet:= ADOCommand.Execute;
Result:= True;
except
Result:= False;
end;
end;
function ADOGetValue(_Indece: integer): Variant;
begin
Result:= ADORecordSet.Fields.Item[_Indece].Value;
end;
end.
I managed to solve, the problem is in my stored Procedure. here I retrieve the returned data: Function Adogetparamval(Paramname: string): Variant; Begin Try Result:= Adocommand.Parameters[Paramname]. Value; except Result:= varEmpty; end;
 end;;
– Anderson de Oliveira
you can post the answer to your question to this way the question ceases to appear unanswered in the list and if anyone has a similar problem you can find the answer o/! #Ficadica. Welcome to [en.so]
– Caputo