Sabtu, 26 Desember 2009

Customizing the DBNavigator

Source :http://delphi.about.com/od/usedbvcl/l/aa090203a.htm

Buttons: array[TNavigateBtn] of TNavButton;

TNavigateBtn =
(nbFirst, nbPrior, nbNext, nbLast, nbInsert,
nbDelete, nbEdit, nbPost, nbCancel, nbRefresh);

type THackDBNavigator = class(TDBNavigator);

type
TForm1 = class(TForm)
...

procedure TForm1.FormCreate(Sender: TObject);
SetupHackedNavigator(DBNavigator1, ImageList1);
end;

type
TForm1 = class(TForm)
...
private
procedure SetupHackedNavigator(const Navigator : TDBNavigator;
const Glyphs : TImageList);


uses Buttons; //!!! don't forget

procedure TForm1.SetupHackedNavigator
(const Navigator : TDBNavigator;
const Glyphs : TImageList);
const
Captions : array[TNavigateBtn] of string =
('Initial', 'Previous', 'Later', 'Final', 'Add',
'Erase', 'Correct', 'Send', 'Withdraw', 'Revive');
(*
Captions : array[TNavigateBtn] of string =
('First', 'Prior', 'Next', 'Last', 'Insert',
'Delete', 'Edit', 'Post', 'Cancel', 'Refresh');

in Croatia (localized):
Captions : array[TNavigateBtn] of string =
('Prvi', 'Prethodni', 'Slijedeci', 'Zadnji', 'Dodaj',
'Obrisi', 'Promjeni', 'Spremi', 'Odustani', 'Osvjezi');
*)

var
btn : TNavigateBtn;
begin
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;

// explained later
OnMouseUp := HackNavMouseUp;
end;
end;
(*SetupHackedNavigator*)


procedure TForm1.HackNavMouseUp
(Sender:TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const MoveBy : integer = 5;
begin
if NOT (Sender is TNavButton) then Exit;

case TNavButton(Sender).Index of
nbPrior:
if (ssCtrl in Shift) then
TDBNavigator(TNavButton(Sender).Parent).
DataSource.DataSet.MoveBy(-MoveBy);
nbNext:
if (ssCtrl in Shift) then
TDBNavigator(TNavButton(Sender).Parent).
DataSource.DataSet.MoveBy(MoveBy);
end;
end;(*HackNavMouseUp*)


type
TForm1 = class(TForm)
...
private
procedure SetupHackedNavigator(const Navigator : TDBNavigator;
const Glyphs : TImageList);
procedure HackNavMouseUp(Sender:TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);


procedure TForm1.DBNavigator1Click
(Sender: TObject; Button: TNavigateBtn);
function CtrlDown : Boolean;
var
State : TKeyboardState;
begin
GetKeyboardState(State);
Result := ((State[vk_Control] And 128) <> 0);
end;
const MoveBy : integer = 5;
begin
case Button of
nbPrior:
if CtrlDown then
DBNavigator1.DataSource.DataSet.MoveBy(-MoveBy);
nbNext:
if CtrlDown then
DBNavigator1.DataSource.DataSet.MoveBy(MoveBy);
end; //case
end;(*DBNavigator2Click*)










Tidak ada komentar:

Posting Komentar

INGIN KERJA DARI RUMAH?