unit ucadProvidencias; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, umstCadastro, Data.DB, Vcl.Grids, Vcl.DBGrids, Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.StdCtrls, Vcl.Mask, Vcl.ComCtrls, Vcl.Buttons, System.ImageList, Vcl.ImgList; // Tentando "Hackear" o TDBNavigator type THackDBNavigator = class(TDBNavigator); type TcadProvidencias = class(TmstCadastro) ImageList1: TImageList; dbgrid_providencias: TDBGrid; DBMemo1: TDBMemo; procedure FormCreate(Sender: TObject); procedure pcClientesChange(Sender: TObject); procedure dtsDBStateChange(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure navPrincipalBeforeAction(Sender: TObject; Button: TNavigateBtn); private { Private declarations } procedure SetupHackedNavigator(const Navigator: TDBNavigator; const Glyphs: TImageList); procedure WMMoving(var Msg: TWMMoving); message WM_MOVING; public id_prov: integer; { Public declarations } end; var cadProvidencias: TcadProvidencias; implementation {$R *.dfm} uses udtmSystem, System.UITypes; procedure TcadProvidencias.dtsDBStateChange(Sender: TObject); begin // inherited; // DBLookupListBox1.Enabled := not(dtsDB.State in [dsEdit, dsInsert]); grpDescricao.Enabled := (dtsDB.DataSet.State in [dsEdit, dsInsert]); dbgrid_providencias.ReadOnly := not(dtsDB.DataSet.State in [dsEdit, dsInsert]); end; procedure TcadProvidencias.FormCreate(Sender: TObject); begin inherited; dtmSystem.tblProvidencias.Open; dtmSystem.tblInadimplencias.Open; SetupHackedNavigator(navPrincipal, ImageList1); id_prov := -1; navPrincipal.Enabled := dtmSystem.VerificarPermissao('CBR.02.05'); end; procedure TcadProvidencias.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin inherited; if Key = VK_ESCAPE then begin Key := 0; Close; end; end; procedure TcadProvidencias.navPrincipalBeforeAction(Sender: TObject; Button: TNavigateBtn); begin case Button of nbPost: begin if dtmSystem.tblProvidenciasTP_FORCAAGENDA.AsString = '' then begin Messagedlg ('Por favor escolha se a providência irá forçar agendamento ou não.', mtWarning, [mbOk], 0); abort; end; end; end; inherited; end; procedure TcadProvidencias.pcClientesChange(Sender: TObject); begin inherited; case pcClientes.ActivePageIndex of 0: begin dtsDB.DataSet := dtmSystem.tblProvidencias; end; 1: begin dtsDB.DataSet := dtmSystem.tblInadimplencias; end; end; end; procedure TcadProvidencias.SetupHackedNavigator(const Navigator: TDBNavigator; const Glyphs: TImageList); const Captions: array [TNavigateBtn] of string = ('Primeiro', 'Anterior', 'Próximo', 'Último', 'Adicionar', 'Excluir', 'Alterar', 'Confirmar', 'Cancelar', 'Atualizar', 'Aplicar Atualizações', 'Cancelar Atualizãções'); (* Captions : array[TNavigateBtn] of string = ('First', 'Prior', 'Next', 'Last', 'Insert', 'Delete', 'Edit', 'Post', 'Cancel', 'Refresh'); *) var btn: TNavigateBtn; begin // função propriamente dita para "hackear" o navigator for btn := Low(TNavigateBtn) to High(TNavigateBtn) do with THackDBNavigator(Navigator).Buttons[btn] do begin // from the Captions const array Caption := Captions[btn]; // the number of images in the Glyph property NumGlyphs := 1; // Remove the old glyph. Glyph := nil; // Assign the custom one Glyphs.GetBitmap(Integer(btn), Glyph); // gylph above text Layout := blGlyphTop; Font.Style := Font.Style - [fsbold]; end; end; procedure TcadProvidencias.WMMoving(var Msg: TWMMoving); var workArea: TRect; begin workArea := Screen.WorkareaRect; with Msg.DragRect^ do begin if left < workArea.left then OffsetRect(Msg.DragRect^, workArea.left - left, 0); if top < workArea.top then OffsetRect(Msg.DragRect^, 0, workArea.top - top); if Right > workArea.Right then OffsetRect(Msg.DragRect^, workArea.Right - Right, 0); if Bottom > workArea.Bottom then OffsetRect(Msg.DragRect^, 0, workArea.Bottom - Bottom); end; end; end.