reading select from stored procedure

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

reading select from stored procedure

Post by jkuiper » Wed 02 Dec 2009 09:14

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)?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 02 Dec 2009 12:54

AfterExecute and AfterFetch events are working, but fields in a dataset are created after these events are arised.

jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

Post by jkuiper » Fri 04 Dec 2009 14:18

Okay. Then I don't know what these events are really doing, but I've got it worked by reading the dataset after executing

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 07 Dec 2009 07:49

You can find information about these events in the MyDAC help.

Post Reply