Ver Mensaje Individual
  #6  
Antiguo 06-09-2012
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 913
Reputación: 23
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Otra alternativa
Código Delphi [-]
{
type
  TMiData=array of integer;

Función: GetValues(Senders:array of TObject; Var AValues:TMiData):Integer;
              Retorna la suma de los items del array AValues, si la suma es menor a cero, no hay selección
}

function TForm3.GetValues(Senders:array of TObject; Var AValues:TMiData):Integer;
var
   i:integer;
begin
     SetLength(AValues,High(Senders)+1);
     Result:=0;
     for i := Low(Senders) to High(Senders) do
     begin
          AValues[i]:=-1;
          if (TRadioGroup(Senders[i]).ItemIndex>-1)   then
             AValues[i]:=StrToInt(TRadioGroup(Senders[i]).Items[ TRadioGroup(Senders[i]).ItemIndex ]);
          Inc(Result,AValues[i]);
     end;
end;

procedure TForm3.BitBtn1Click(Sender: TObject);
var
  AValues:TMiData;
  i:Integer;
  Prefix:string;
begin
     {             AValues[0]   AValue[1]  }
     if GetValues([RadioGroup1, RadioGroup2],AValues)<0 then
     begin
          ShowMessage('Sin selección');
          Exit;
     end;

     With ADOQuery1 Do
     Begin
          Close;
          SQL.Clear;
          SQL.Add('SELECT * FROM A_CATALOGO WHERE ');

           Prefix:='';
           if AValues[0]>-1 then {Corresponde a RadioGroup1}
           begin
                Prefix:=' AND';
                SQL.Add(Format('(AÑO = %d)',[AValues[0]]));
           end;

           if AValues[1]>-1 then  {Corresponde a RadioGroup2}
           begin
               SQL.Add(Format('%s (MES = %d)',[Prefix, AValues[1]]));
               Prefix:=' AND';
           end;

          Open;
     End;
   
end;

Saludos cordiales
Responder Con Cita