Delphhi Edit Record Problem

Asked

Viewed 51 times

0

Good evening folks! I recently joined the Delphi world and created some client registration applications using the Mysql database. The records added to the database are shown in a Dbgrid and when double-clicking on the record, opens the Pagecontrol page where the data is recorded, deleted and edited. So far so good, but when clicking the button to edit the record, all Dbedits of the registration page change to the last registration done in the system. Someone could help me solve this mistake?

Click from the Dbgrid:

procedure TFrmUsuarios.DBGrid1DblClick(Sender: TObject); begin dm.tb_Usuarios.Active := True; dm.tb_Usuarios.Edit; txt_Nome.Text := dm.sql_con_usuariosnome.Value; txt_Id.Text := IntToStr (dm.sql_con_usuariosid.Value); txt_Senha.Text:= dm.sql_con_usuariossenha.Value; ChamarDetalhes; ConfigBotoes; HabilitarCampos; end;

Click the Edit button:

procedure TFrmUsuarios.btn_alterarClick(Sender: TObject); begin dm.tb_Usuarios.Active := True; dm.tb_Usuarios.Edit; ChamarDetalhes; ConfigBotoes; HabilitarCampos; end;

From Now Thank You!!

  • We need to know what these methods do: Call Details, Configbotoes and Enable Fields.

  • There are some inconsistencies between the code you showed and what you wrote. Datasource on your Dbgrid is linked to which data component (txt_Nome.Text). That one dm.sql_con_usuariosnome.Value is a Tfield? if yes, of which Ttable?

1 answer

-1

Good evening friend, for a good practice is you inform the

first

of your date component, doing so:

procedure TFrmUsuarios.btn_alterarClick(Sender: TObject);
begin
  dm.tb_Usuarios.Active := True;
  dm.tb_Usuarios.First;
  dm.tb_Usuarios.Edit;
  ChamarDetalhes;
  ConfigBotoes;
  HabilitarCampos;
end;

If you want to use the selected record, just use the

Filter.

dm.tb_Usuarios.Filtered := False;
dm.tb_Usuarios.Filter   := 'CAMPO_CHAVE = ' + IntToStr(dm.sql_con_usuariosid.AsInteger);
dm.tb_Usuarios.Filtered := True;

I hope it helps. Hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.