Fórum O que há de errado nesse codigo #157179

01/05/2003

0

Este codigo está executando a operação , mas não para e dá um erro dizendo que é uma operação inválida, (insertMode ou editMode)

procedure TfmSaida.BitBtn7Click(Sender: TObject);
var
sn: integer;
begin
if not tblSaida.eof=true then begin
sn:=Application.Messagebox(´Tem certeza que deseja excluir esse registro ?´,´Confirmação´,36);
if sn=6 then begin

fmCadastro.tblCadastro.Edit;
if FmSaida.tblSaidaQuantidade.Value <> fmCadastro.tblCadastroQuantidade.Value then
fmCadastro.tblCadastroQuantidade.Value:= fmCadastro.tblCadastroQuantidade.Value - fmSaida.tblSaidaQuantidade.Value;
fmCadastro.tblCadastroQuantidadeTotal.Value:= fmCadastro.tblCadastroQuantidadeTotal.Value - fmSaida.tblSaidaQuantidade.Value;
fmCadastro.tblCadastroCustoTotal.Value:= fmCadastro.tblCadastroCustoTotal.Value - fmSaida.tblSaidaCustoTotal.Value;
fmCadastro.tblCadastroCusto.Value:= fmCadastro.tblCadastroCustoTotal.Value / fmCadastro.tblCadastroQuantidadeTotal.Value;
fmCadastro.tblCadastro.Post;
tblSaida.delete;
end
else
fmCadastro.tblCadastro.Edit;
fmCadastro.tblCadastroQuantidade.Value:=0;
fmCadastro.tblCadastroCusto.Value:=0;
fmCadastro.tblCadastroQuantidadeTotal.Value:=0;
fmCadastro.tblCadastroCustoTotal.Value:=0;
fmCadastro.tblCadastro.Post;
tblSaida.Delete;
end;
end;


Clenio

Clenio

Responder

Posts

01/05/2003

Adilsond

procedure TfmSaida.BitBtn7Click(Sender: TObject);
begin
  if tblSaida.EOF then
     Exit;
  if Application.Messagebox(´Tem certeza que deseja excluir esse registro ?´,
       ´Confirmação´,MB_YESNO) = IDNO then
     Exit;
  fmCadastro.tblCadastro.Edit;
  if tblSaidaQuantidade.Value <> fmCadastro.tblCadastroQuantidade.Value then
     begin
       fmCadastro.tblCadastroQuantidade.Value :=
         fmCadastro.tblCadastroQuantidade.Value - tblSaidaQuantidade.Value;
       fmCadastro.tblCadastroQuantidadeTotal.Value :=
         fmCadastro.tblCadastroQuantidadeTotal.Value - tblSaidaQuantidade.Value;
       fmCadastro.tblCadastroCustoTotal.Value :=
         fmCadastro.tblCadastroCustoTotal.Value - tblSaidaCustoTotal.Value;
       fmCadastro.tblCadastroCusto.Value :=
         fmCadastro.tblCadastroCustoTotal.Value /
         fmCadastro.tblCadastroQuantidadeTotal.Value;
     end
  else
     begin
       fmCadastro.tblCadastroQuantidade.Value := 0;
       fmCadastro.tblCadastroCusto.Value := 0;
       fmCadastro.tblCadastroQuantidadeTotal.Value := 0;
       fmCadastro.tblCadastroCustoTotal.Value := 0;
     end;
  tblSaida.Delete;
  fmCadastro.tblCadastro.Post;
end;



Responder

Gostei + 0

01/05/2003

Samth

Primeiro de tudo nunca se coloca um END antes de ELSE.

Quando se fala em IF...Then e ELSE só se pode fazer referência a um comando por vez, ou então o Delphi faz o código direto, sem considerá-los, como aconteceu com você. Então você tem que usar uma actionlist (na paleta standart do delphi) e colocar os comandos que você quer realizar assim:

procedure actionlistAção1 [color=blue:50a5ad17bf]//exemplo de ação hipotética ´Ação1´[/color:50a5ad17bf]
begin
fmCadastro.tblCadastro.Edit;
fmCadastro.tblCadastroQuantidade.Value:=0;
fmCadastro.tblCadastroCusto.Value:=0;
fmCadastro.tblCadastroQuantidadeTotal.Value:=0;
fmCadastro.tblCadastroCustoTotal.Value:=0;
fmCadastro.tblCadastro.Post;
tblSaida.Delete;
end;

procedure actionlistAção2
begin
fmCadastro.tblCadastroQuantidade.Value:= fmCadastro.tblCadastroQuantidade.Value - fmSaida.tblSaidaQuantidade.Value;
fmCadastro.tblCadastroQuantidadeTotal.Value:= fmCadastro.tblCadastroQuantidadeTotal.Value - fmSaida.tblSaidaQuantidade.Value;
fmCadastro.tblCadastroCustoTotal.Value:= fmCadastro.tblCadastroCustoTotal.Value - fmSaida.tblSaidaCustoTotal.Value;
fmCadastro.tblCadastroCusto.Value:= fmCadastro.tblCadastroCustoTotal.Value / fmCadastro.tblCadastroQuantidadeTotal.Value;
fmCadastro.tblCadastro.Post;
tblSaida.delete;
end;

procedure Buton.click
var
sn: integer;
begin
if not tblSaida.eof=true then
sn:=Application.Messagebox(´Tem certeza que deseja excluir esse registro ?´,´Confirmação´,36);
begin
if sn=6 then
fmCadastro.tblCadastro.Edit;
begin
if FmSaida.tblSaidaQuantidade.Value <> fmCadastro.tblCadastroQuantidade.Value then
Ação2.Execute
else
Ação1.Execute;
end;
end;
end;

Agora eu acho que seu código vai funcionar, porque eu não testei...
Espero ter ajudado.


Responder

Gostei + 0

01/05/2003

4_olho

Como diz aquela propaganda de uma montadora de automóveis : ´Está na hora de rever seus conceitos´

Observe o código abaixo, extraido do Help on-line do Delphi 6.

if J <> 0 then

begin
Result := I/J;
Count := Count + 1;
end
else if Count = Last then
Done := True
else
Exit;

Este código vai diretamente contra o que escreveu em seus dois primeiros parágrafos.

AO CLENIO
O fato de algum de seu if não parar é porque a comparação nunca se verifica como verdadeira. Veja a dica dada por AdilsonD e veja se está tudo bem ´empacotado´ pelos blocos BEGIN..END.

Assim que este problema estiver resolvido, o erro de operação inválida deve se resolver sozinho.

Boa sorte !


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar