Tenho a seguinte tabela:
campo1(chave)
campo2
No formshow monto a query assim:
  with DM.qryManut do
   begin
     sql.clear;
     sql.add('SELECT CAMPO1, CAMPO2 FROM TABELA');
     sql.add(' WHERE CAMPO1 = :pcampo1');
   end;
No botão de inclusão tenho a seguinte rotina:
  with DM.cdsManut do
   begin
     if not Active then
      begin
        DM.qryManut.parambyname('pcampo1').asinteger := strtoint(trim
(meCodigo.text));
        open;
      end;
     if consulta then
        edit
     else
        insert;
     fieldbyname('CAMPO1').asinteger := strtoint(trim(meCodigo.Text));
     fieldbyname('CAMPO2').asstring := trim(edtDescr.Text);

     post;
   end;
Se selecionar no campo1 = 5 e quiser alterar para 6, funciona legal, 
ou seja, altera a chave. 
Porém em outra tela tenho a seguinte tabela
campo1(chave)
campo2(chave)
campo3
campo4
campo5
No formshow monto a query
  with DM.qryManut do
   begin
     sql.clear;
     sql.add('SELECT CAMPO1, CAMPO2, CAMPO3, CAMPO4 ,CAMPO5 FROM 
TABELA');
     sql.add(' WHERE CAMPO1 = :pcampo1');
     sql.add(' WHERE CAMPO2 = :pcampo2');
   end;
No botão de inclusão tenho a seguinte rotina
  with DM.cdsManut do
   begin
     if not Active then
      begin
        DM.qryManut.parambyname('pcampo1').asinteger := strtoint(trim
(meCodigo1.text));
        DM.qryManut.parambyname('pcampo2').asinteger := strtoint(trim
(meCodigo2.text));
        open;
      end;
     if consulta then
        edit
     else
        insert;
     fieldbyname('CAMPO1').asinteger := strtoint(trim
(meCodigo1.Text));
     fieldbyname('CAMPO2').asinteger := strtoint(trim
(meCodigo2.Text));
     fieldbyname('CAMPO3').asstring := trim(descr1.Text);
     fieldbyname('CAMPO4').asstring := trim(descr2.Text);
     fieldbyname('CAMPO5').asstring := trim(descr3.Text);

     post;
   end;
Se selecionar no campo1 = 5 e campo2 = 5 e quiser alterar o campo2 
para 6, não funciona. Inclui um novo registro. Ou seja, quando é 
chave composta ele não altera, inclui. Alguem sabe se tenho que 
alterar alguma propriedade no CDS, DSP ou Query? Uso D7 e edit´s e 
maskedit´s. Estou perguntando, pois talvez não seja necessário fazer 
o INSERT/UPDATE na mão.
Obrigado.


Responder a