Page 1 of 1

reading select from stored procedure

Posted: Wed 02 Dec 2009 09:14
by jkuiper
I have a stored proc that calls several other procs. After the final result I give a SELECT back to my Delphi application. This works:

Code: Select all

procedure TForm2.Button1Click(Sender: TObject);
begin
  StKosten.Prepare;
  StKosten.Params[0].Value := 34;
  StKosten.ExecProc;
  try
    with memo1.Lines do
    begin
      add(floattostr(StKosten.FieldByName('nettoweigth').AsFloat));
      add(floattostr(StKosten.FieldByName('palweigth').AsFloat));
      add(floattostr(StKosten.FieldByName('totalsales').AsFloat));
    end;
  except
    showmessage('reading failed');
  end;
end;
But if I put the code from try..except into AfterExecute or AfterFetch

Code: Select all

procedure TForm2.StKostenAfterExecute(Sender: TObject; Result: Boolean);
begin
  try
    with memo1.Lines do
    begin
      add(floattostr(StKosten.FieldByName('nettoweigth').AsFloat));
      add(floattostr(StKosten.FieldByName('palweigth').AsFloat));
      add(floattostr(StKosten.FieldByName('totalsales').AsFloat));
    end;
  except
    showmessage('reading failed');
  end;
end;
Delphi comes with this errormessage:
---------------------------
Debugger Exception Notification
---------------------------
Project Project3.exe raised exception class EDatabaseError with message 'StKosten: Field 'nettoweigth' not found'.
---------------------------
I really don't understand why. Are the events in TMyStoredProc out of order (not working)?

Posted: Wed 02 Dec 2009 12:54
by Dimon
AfterExecute and AfterFetch events are working, but fields in a dataset are created after these events are arised.

Posted: Fri 04 Dec 2009 14:18
by jkuiper
Okay. Then I don't know what these events are really doing, but I've got it worked by reading the dataset after executing

Posted: Mon 07 Dec 2009 07:49
by Dimon
You can find information about these events in the MyDAC help.