unit uFichasEmpleadoReportController; interface uses Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleFichasEmpleadoReport, uEmpleadosController; type IFichasEmpleadoReportController = interface ['{8E43F55F-7D5A-4778-8523-7C105EAEB1AB}'] procedure Preview(const AFichaID : String); procedure Print(const AFichaID : String); end; TFichasEmpleadoReportController = class(TInterfacedObject, IFichasEmpleadoReportController) private FDataModule : IDataModuleFichasEmpleadoReport; function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; public constructor Create; destructor Destroy; override; procedure Preview(const AFichaID : String); procedure Print(const AFichaID : String); end; implementation uses uROTypes, uEditorRegistryUtils, uIEditorFichasEmpleadoPreview, uEditorPreview, uDataModuleEmpleados, uEditorBase, cxControls; { TFichasEmpleadoReportController } constructor TFichasEmpleadoReportController.Create; begin FDataModule := TDataModuleEmpleados.Create(Nil); end; function TFichasEmpleadoReportController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; begin Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf); end; destructor TFichasEmpleadoReportController.Destroy; begin FDataModule := NIL; inherited; end; procedure TFichasEmpleadoReportController.Preview(const AFichaID : String); var AStream: Binary; AEditor : IEditorFichasEmpleadoPreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetReport(AFichaID); try CreateEditor('EditorFichasEmpleadoPreview', IEditorFichasEmpleadoPreview, AEditor); AEditor.LoadFromStream(AStream); finally AStream.Free; end; finally HideHourglassCursor; end; if Assigned(AEditor) then AEditor.Preview; end; procedure TFichasEmpleadoReportController.Print(const AFichaID : String); var AStream: Binary; AEditor : IEditorFichasEmpleadoPreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetReport(AFichaID); try CreateEditor('EditorFichasEmpleadoPreview', IEditorFichasEmpleadoPreview, AEditor); AEditor.LoadFromStream(AStream); finally AStream.Free; end; finally HideHourglassCursor; end; if Assigned(AEditor) then AEditor.Print end; end.