[ Pobierz całość w formacie PDF ]
.Figure 15.6 Buttons on the TDBNavigator controlInsert record Delete current recordNext record Post record editsFirst record Refresh recordsPrior record Cancel record editsLast record Edit current recordThe following table describes the buttons on the navigator.Table 15.8 TDBNavigator buttonsButton PurposeFirst Calls the dataset s First method to set the current record to the first record.Prior Calls the dataset s Prior method to set the current record to the previous record.Next Calls the dataset s Next method to set the current record to the next record.Last Calls the dataset s Last method to set the current record to the last record.Insert Calls the dataset s Insert method to insert a new record before the current record, andset the dataset in Insert state.Delete Deletes the current record.If the ConfirmDelete property is True it prompts forconfirmation before deleting.Edit Puts the dataset in Edit state so that the current record can be modified.Post Writes changes in the current record to the database.Cancel Cancels edits to the current record, and returns the dataset to Browse state.Refresh Clears data control display buffers, then refreshes its buffers from the physical table orquery.Useful if the underlying data may have been changed by another application.Choosing navigator buttons to displayWhen you first place a TDBNavigator on a form at design time, all its buttons arevisible.You can use the VisibleButtons property to turn off buttons you do not want touse on a form.For example, when working with a unidirectional dataset, only the15-28 Dev el oper s Gui deNa v i g a t i n g a n d ma n i p u l a t i n g r e c o r d sFirst, Next, and Refresh buttons are meaningful.On a form that is intended forbrowsing rather than editing, you might want to disable the Edit, Insert, Delete, Post,and Cancel buttons.Hiding and showing navigator buttons at design timeThe VisibleButtons property in the Object Inspector is displayed with a + sign toindicate that it can be expanded to display a Boolean value for each button on thenavigator.To view and set these values, click on the + sign.The list of buttons thatcan be turned on or off appears in the Object Inspector below the VisibleButtonsproperty.The + sign changes to a (minus) sign, which you can click to collapse thelist of properties.Button visibility is indicated by the Boolean state of the button value.If a value is setto True, the button appears in the TDBNavigator.If False, the button is removed fromthe navigator at design time and runtime.Note As button values are set to False, they are removed from the TDBNavigator on theform, and the remaining buttons are expanded in width to fill the control.You candrag the control s handles to resize the buttons.Hiding and showing navigator buttons at runtimeAt runtime you can hide or show navigator buttons in response to user actions orapplication states.For example, suppose you provide a single navigator fornavigating through two different datasets, one of which permits users to edit records,and the other of which is read-only.When you switch between datasets, you want tohide the navigator s Insert, Delete, Edit, Post, Cancel, and Refresh buttons for the read-only dataset, and show them for the other dataset.For example, suppose you want to prevent edits to the OrdersTable by hiding theInsert, Delete, Edit, Post, Cancel, and Refresh buttons on the navigator, but that you alsowant to allow editing for the CustomersTable.The VisibleButtons property controlswhich buttons are displayed in the navigator.Here s one way you might code theOnEnter event handler:procedure TForm1.CustomerCompanyEnter(Sender :TObject);beginif Sender = CustomerCompany thenbeginDBNavigatorAll.DataSource := CustomerCompany.DataSource;DBNavigatorAll.VisibleButtons := [nbFirst,nbPrior,nbNext,nbLast];endelsebeginDBNavigatorAll.DataSource := OrderNum.DataSource;DBNavigatorAll.VisibleButtons := DBNavigatorAll.VisibleButtons + [nbInsert,nbDelete,nbEdit,nbPost,nbCancel,nbRefresh];end;end;Us i ng dat a c ont r ol s 15-29Na v i g a t i n g a n d ma n i p u l a t i n g r e c o r d sDisplaying fly-over helpTo display fly-over help for each navigator button at runtime, set the navigatorShowHint property to True.When ShowHint is True, the navigator displays fly-byHelp Hints whenever you pass the mouse cursor over the navigator buttons.ShowHint is False by default.The Hints property controls the fly-over help text for each button.By default Hints isan empty string list.When Hints is empty, each navigator button displays defaulthelp text.To provide customized fly-over help for the navigator buttons, use theString list editor to enter a separate line of hint text for each button in the Hintsproperty.When present, the strings you provide override the default hints providedby the navigator control.Using a single navigator for multiple datasetsAs with other data-aware controls, a navigator s DataSource property specifies thedata source that links the control to a dataset.By changing a navigator s DataSourceproperty at runtime, a single navigator can provide record navigation andmanipulation for multiple datasets.Suppose a form contains two edit controls linked to the CustomersTable andOrdersTable datasets through the CustomersSource and OrdersSource data sourcesrespectively.When a user enters the edit control connected to CustomersSource, thenavigator should also use CustomersSource, and when the user enters the edit controlconnected to OrdersSource, the navigator should switch to OrdersSource as well.Youcan code an OnEnter event handler for one of the edit controls, and then share thatevent with the other edit control
[ Pobierz całość w formacie PDF ]