Utilisation de Firedac pour exécuter une procédure stockée SQL

J'essaie de comprendre comment exécuter une procédure stockée en utilisant Firedac

unit DataLayer.OilCommanderConnection; interface uses FireDAC.Phys.FB, Generics.Collections, Model.Sample, Model.Batch, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQL, Data.DB, FireDAC.Comp.Client, FireDAC.Phys.MSSQL, FireDAC.DApt, FireDAC.Comp.UI ; type TOilCommanderConnection = class ssortingct private public Connection : TFDConnection; function GetSampleTypesForBatch(Batch : TBatch) : Boolean; function Connect:Boolean; constructor Create; destructor Destroy; override; end; implementation uses SysUtils ; function TOilCommanderConnection.Connect:Boolean; var OK : Boolean; begin OK := true; Connection := TFDConnection.Create(nil); try Connection.Params.LoadFromFile('MSSQL.ini'); finally Result := OK; end; end; function TOilCommanderConnection.GetSampleTypesForBatch(Batch : TBatch) : Boolean; var StoredProc : TFDStoredProc; begin Connect; StoredProc := TFDStoredProc.Create(nil); try StoredProc.Connection := Connection; StoredProc.StoredProcName := 'GetSampleTypesForBatch'; StoredProc.Prepare; StoredProc.FetchOptions.Items := StoredProc.FetchOptions.Items - [fiMeta]; with StoredProc.Params do begin Clear; with Add do begin Name := 'BatchNo'; ParamType := ptInput; DataType := ftSsortingng; Size := 6; end; end; StoredProc.StoredProcName := 'GetSampleTypesForBatch'; StoredProc.Prepare; StoredProc.Params[0].Value := Batch.RackNo; StoredProc.ExecProc; while not StoredProc.Eof do begin //StoredProc.FieldByName('').AsS StoredProc.Next; end; finally FreeAndNil(StoredProc); end; Result := true; end; constructor TOilCommanderConnection.Create; begin inherited; Connection := TFDConnection.Create(nil); end; destructor TOilCommanderConnection.Destroy; begin if Assigned(Connection) then FreeAndNil(Connection); inherited; end; end. 

Je reçois un message d'erreur à la première occurrence de la ligne

StoredProc.Prepare;

Voici le message

————————— Notification d'exception du débogueur

Project RefractiveIndexTests.exe a levé une exception de class d'exception avec le message 'Objet de l'usine pour la class {3E9B315B-F456-4175-A864-B2573C4A2201} est manquant. Pour l'save, vous pouvez déposer le composant [TFDGUIxWaitCursor] dans votre projet '.

J'ai appelé la fonction en utilisant

 OilCommanderConnection.GetSampleTypesForBatch(batch); 

d'un projet de test.

le tutoriel que j'ai lu n'a pas expliqué ce qu'il fallait faire à propos de cette situation.

J'ai essayé d'append TFDGUIxWaitCursor dans mon projet comme le message d'erreur le suggère mais cela n'a fait aucune différence. Je me request si ce problème est lié au fait que je garde la logique de connection à la database dans une unité séparée de mon formulaire principal. J'aimerais pouvoir séparer mon interface user de ma couche de données.

En fonction du type de votre application, incluez l'une des unités suivantes dans une clause "uses":

  • FireDAC.VCLUI.Wait – pour les applications VCL;
  • FireDAC.FMXUI.Wait – pour les applications FireMonkey;
  • FireDAC.ConsoleUI.Wait – pour les applications console / non-visuelles.