Subject
Author dark_wolf1812
Hi People.

Sorry for the question again, but I didn't find a solution.

I have 2 tables in the form. One of them is RequestLive:= False, and
the other is RequestLive:= True.
One of them, so, is for edition. When I change to the next register,
the edition table change too, with a routine in the datachange:

procedure TFrmCadPosicao.DsQryTabelaDataChange(Sender:
TIB_StatementLink;
Statement: TIB_Statement; Field: TIB_Column);
var
AUXCodigo: string;
begin
inherited;
if QryTabela.Active then
begin
if not (QryTabela.FieldByName('TB001_CODIGO_POSICAO').AsString
= '') then
begin
AUXCodigo:= QryTabela.FieldByName
('TB001_CODIGO_POSICAO').AsString;
if not (QryEdicaoTabela.Active) then
QryEdicaoTabela.Open;
QryEdicaoTabela.Locate('TB001_CODIGO_POSICAO',AUXCodigo,
[lopCaseInsensitive]);
end
else
begin
SbAlterar.Enabled:= False;
SbExcluir.Enabled:= False;
SbPesquisar.Enabled:= False;
end;
end;
end;



When I put in edition, and save, it's ok, but when i'm inserting
data, the problem appears. "The field xxxx (key) is required".
But I generate a number that is to be inserted in the pkfield.
Look:

procedure TFrmCadPosicao.SbGravarClick(Sender: TObject);
var
sValorCampoTabela: String;
begin
inherited;
PnlCentral.SetFocus;
if not(FNCValidaCampos) then
Exit;
FrmMenuPrincipal.PROIniciaTransacao; (* StartTransaction *)
Chave:= QryEdicaoTabela.FieldByName(sCampoPK).AsString;
try
if QryEdicaoTabela.State = dssEdit then
begin
STP_ALT_POSICAO.Prepare;
STP_ALT_POSICAO.ParamByName('TB001_CODIGO_POSICAO').AsInteger:=
StrToInt(Chave);
STP_ALT_POSICAO.ParamByName('TB001_DESCRICAO').AsString:=
QRYEDICAOTABELA.FieldByName('TB001_DESCRICAO').AsString;
STP_ALT_POSICAO.ParamByName('TB001_OBSERVACAO').AsString:=
QRYEDICAOTABELA.FieldByName('TB001_OBSERVACAO').AsString;
STP_ALT_POSICAO.ExecProc;
end;
if QryEdicaoTabela.State = dssInsert then
begin
with DataModulo.QryPesquisa do (* I search a new number *)
begin
Close;
SQL.Clear;
SQL.Add(sSQL);
SQL.Add('ORDER BY ' + sCampoPK);
Open;
if RecordCount > 0 then
begin
Last;
Chave:= IntToStr(StrToInt(FieldByName(sCampoPK).AsString)
+ 1);
end
else
Chave:= '1';
end;
STP_INS_POSICAO.Prepare;
STP_INS_POSICAO.ParamByName('TB001_CODIGO_POSICAO').AsInteger:=
StrToInt(Chave);
STP_INS_POSICAO.ParamByName('TB001_DESCRICAO').AsString:=
QRYEDICAOTABELA.FieldByName('TB001_DESCRICAO').AsString;
STP_INS_POSICAO.ParamByName('TB001_OBSERVACAO').AsString:=
QRYEDICAOTABELA.FieldByName('TB001_OBSERVACAO').AsString;
STP_INS_POSICAO.ExecProc;
end;
DataModulo.TrnSistema.Commit;
except
raise;
end;
sValorCampoTabela:= Chave;
QryEdicaoTabela.DisableControls;
QryEdicaoTabela.Close;
QryEdicaoTabela.Open;
QryEdicaoTabela.EnableControls;
QryTabela.Disablecontrols;
QryTabela.Close;
QryTabela.Open;
QryTabela.Locate(sCampoPK,sValorCampoTabela,[lopCaseInsensitive]);
QryTabela.EnableControls;
AtualizaBotoes;
end;


My Stored Procedure of insertion:

CREATE PROCEDURE INS_POSICAO (
TB001_CODIGO_POSICAO INTEGER,
TB001_DESCRICAO VARCHAR(50),
TB001_OBSERVACAO VARCHAR(250)
) AS
BEGIN
INSERT INTO TB001_POSICAO (
TB001_CODIGO_POSICAO,
TB001_DESCRICAO,
TB001_OBSERVACAO)
VALUES (
:TB001_CODIGO_POSICAO,
:TB001_DESCRICAO,
:TB001_OBSERVACAO);
END


My Stored Procedure of Edition:

CREATE PROCEDURE ALT_POSICAO (
TB001_CODIGO_POSICAO INTEGER,
TB001_DESCRICAO VARCHAR(50),
TB001_OBSERVACAO VARCHAR(250)
) AS
BEGIN
UPDATE TB001_POSICAO
SET TB001_DESCRICAO = :TB001_DESCRICAO,
TB001_OBSERVACAO = :TB001_OBSERVACAO
WHERE (TB001_CODIGO_POSICAO = :TB001_CODIGO_POSICAO);
END

I don't know what to do... Does someone have a solution?