Ver Mensaje Individual
  #2  
Antiguo 29-01-2021
Avatar de movorack
[movorack] movorack is offline
Miguel A. Valero
 
Registrado: feb 2007
Ubicación: Bogotá - Colombia
Posts: 1.346
Reputación: 20
movorack Va camino a la famamovorack Va camino a la fama
Hola,

FindParam busca el parámetro dentro de la consulta y devuelve el objeto. En caso de no existir, en Delphi devuelve un nil

Código Delphi [-]
  AQuery.SQL.Text := 'SELECT * FROM TABLA WHERE CAMPO1 = :CAMPO1';

  if CheckBox1.Checked then
    AQuery.SQL.Add('  AND CAMPO2 = :CAMPO2';

  AQuery.Params.ParamsByName('CAMPO1').Value := Valor1;

  if Assigned(AQuery.Params.FindParam('CAMPO2')) then
    AQuery.Params.ParamsByName('CAMPO2').Value := Valor2;

GetParamList, Permite hacer una búsqueda similar pero con mas de un parámetro. En este caso llena un TList.

Código Delphi [-]
var
  i: integer;
  ListaP: TList < TParam >;
begin
  AQuery.SQL.Text := 'SELECT * FROM TABLA WHERE CAMPO1 = :CAMPO1';

  if CheckBox1.Checked then
    AQuery.SQL.Add('  AND CAMPO2 = :CAMPO2';

  if CheckBox2.Checked then
    AQuery.SQL.Add('  AND CAMPO3 = :CAMPO3';

  if CheckBox3.Checked then
    AQuery.SQL.Add('  AND CAMPO4 = :CAMPO4';

  AQuery.Params.ParamsByName('CAMPO1').Value := Valor1;
  
  ListaP := TList < TParam >.Create;
  try
    AQuery.Params.GetParamList(ListaP, ['CAMPO2;CAMPO3;CAMPO4']);
    
    for i := 0 to ListaP.Count - 1 do
    begin
      //Aquí puedo interactuar con los parámetros presentes en la lista
    end;
  finally
    ListaP.free;
  end;    
end;
__________________
Buena caza y buen remar... http://mivaler.blogspot.com
Responder Con Cita