Hola
Lo que haces es una inserción con un botón, en ese mismo momento se hace la comparación:
Coloca un query nuevo en el form, lo enlazas a la tabla.
Supongo que tendras un edit o dbedit donde escribes el ID, entonces lo haces asi:
Código Delphi
[-]
procedure TF_Importa.BitBtn1Click(Sender: TObject);
var
F:TIBInputDelimitedFile;
i:integer;
begin
If dit1.Text <> '' then Begin
TuQuery.Active:= false;
TuQuery.SQL.Text:= 'Select ID from TuTabla Where ID = :cod ';
TuQuery.Parameters.ParamByName('cod').Value := Edit1.Text; TuQuery.Active := true;
IF TuQueryID.AsString = Edit1.Text then begin
MessageDlg('ID ya existe, favor seleccionar otro',mtError,[mbOK],0);
Edit1.Text:= '';
end
else
F_Confirmacio := TF_Confirmacio.Create(self);
F_Confirmacio.Label1.Caption:= 'Importem arxiu';
try
If F_Confirmacio.ShowModal = mrok then
begin
F_ModulDades.Act_Girona_Hist.Close;
F_ModulDades.Act_Girona_Hist.Open;
F_ModulDades.Act_Girona_Hist.Last;
i:=F_ModulDades.Act_Girona_HistID.Value+1;
F_ModulDades.Act_Girona_Hist.Append;
F_ModulDades.Act_Girona_HistID.Value:=i;
F_Importa.IBSQLImporta.SQL.Text := 'Insert into RE0006AGT values(:ID, :ID_REBUT, :ID_ARBITRE, :NOM, ATA, :TITOL, :CODI_CLUB, :CANON, :PASSADA)';
F := TIBInputDelimitedFile.Create;
try
F.ColDelimiter:=';';
If OpenDialog1.Execute then
begin
F.Filename:=OpenDialog1.FileName;
end;
F_Importa.IBSQLImporta.BatchInput(F);
finally
F.Free;
end;
Posa_S.ExecSQL;
end;
finally
F_Confirmacio.Free;
end;
Showmessage('Procés finalitzat');
end;
Si el ID ya existe no guardara nada y dara el foco al edit, de lo contrario lo grabara.
Saludos