Tengo un formulario que muestra las diferentes extracciones de datos personalizadas.
Cada extracción de datos es un SQL (SELECT ... FROM ... WHERE ...)
El SQL se asigno al DataSet xResultado.SelectSQL.
En un panel se crean tantos componentes TEdit como parámetros haya en el WHERE. La propiedad Tag del TEdit es el indice del parámetro.
Hay un botón para ejecutar la consulta pasándole los parámetros. Este es el evento que llama a TDMExtraccionDatos.Ejecutar.
Te dejo el código por si te sirve de algo...
Código Delphi
[-]
procedure TFMExtraccionDatos.BEjecutaClick(Sender: TObject);
var
i : integer;
begin
inherited;
if (PCMain.ActivePage = TSFicha) then
begin
for i := 0 to PNLFicha.ComponentCount - 1 do
begin
if (PNLFicha.Components[i] is TEdit) then
begin
with DMExtraccionDatos.xResultado.Params[TEdit(PNLFicha.Components[i]).Tag] do
begin
if (DataType in [ftString, ftWideString]) then
AsString := TEdit(PNLFicha.Components[i]).Text;
if (DataType = ftFloat) then
AsFloat := StrToFloatDef(TEdit(PNLFicha.Components[i]).Text, 0);
if (DataType in [ftInteger, ftSmallint]) then
AsInteger := StrToIntDef(TEdit(PNLFicha.Components[i]).Text, 0);
if (DataType = ftDateTime) then
AsDateTime := StrToDateTime(TEdit(PNLFicha.Components[i]).Text);
end;
end;
end;
DMExtraccionDatos.Ejecutar;
end
else
begin
PCMain.ActivePage := TSFicha;
PCMainChange(Sender);
CreaParametros;
end;
end;