How to Convert a TParams (TQuery) Object to TParameters (ADO) object.?

Viewed 584

I am working on a legacy code which contains some TQuery components. I was trying to create a function which convert the TQuery Parameters into TParameters so that i can assign them into the Parameters property of an ADO Component (Like ADOQuery or ADODataSet).

I tried the following which i got from internet.

function ConvertToADOParms(Owner: TADODataset; aParams: TParams): TParameters;

var i: integer;

begin
// Convert a standard TParams object to an ADO-specific TParameters object
 Result :=nil;
 try
  if aParams = nil then exit;
  Result :=TParameters.create( Owner, TParameter);
  for i:=0 to aParams.count - 1 do
   begin
    if aParams[i] = nil then continue;
    with Result.AddParameter do
     begin
      Name := aParams[i].Name;
      Datatype :=aParams[i].DataType;
      Direction :=TParameterDirection(aParams[i].ParamType);
      Size :=aParams[i].size;
      Value :=aParams[i].value;
     end;
   end;
 except
  on e:exception do
    begin
     Result :=nil;
     showmessage('Could not convert standard parameter object to ADO parameter object: '+e.message);
    end;
 end;
end;

But i am getting Invalid Class Typecast Error. When i debug the code i found that the error occurs at this function in ADODB unit

function TParameters.GetCommand: TADOCommand;
begin
  Result := GetOwner as TADOCommand;
end;

Help Please. I am Using Delphi 5

1 Answers
Related