Documents
NextGrid & NextDBGrid
- Html Column Tutorial
- Upgrade existing projects for loading changes
- Edit events in NextGrid
- NextGrid Vista Style
- NextGrid How To
- Integrating Inplace Editors
- NextGrid Slide Style Tutorial
- InputLine Tutorial
- FieldChooser Tutorial
- Using Editors in runtime
- Grid Report Tutorial
NextGrid
- TreeColumn Tutorial
- NextGrid Quick Start
- Custom Draw in NextGrid
- Export to XML from NextGrid
- Optimize NextGrid
- NextGrid Custom Sorting
- VirtualColumn Tutorial
- Graphic Column Tutorial
NextDBGrid
- NextDBGrid Quick Start
- NextDBGrid Events
- NextDBGrid How To
- Sorting records in NextDBGrid
- LookupColumn Tutorial
NextInspector
- NextInspector Advanced tutorial
- ToolbarItem tutorial
- NextDBInspector Tutorial
- NextInspector Item Types
- Map VCL property to item
- NextInspector Quick Start
NextSheet
NextCollection
- NxAlertWindow Tutorial
- NxInfoPanel Tutorial
- Vista Styled Panels
- NxPathControl and NxNotebook tutorial
- NxPathControl Quick Start
- NxFlipPanel and NxHeaderPanel Quick Start
- NxOutlookBar Tutorial
- NxPageControl and NxNotebook Quick Start
- NxButton Tutorial
Misc
- Component Names Change
- NxComboBox styles
- Numeric FormatMask
- NxVirtualDataSet tutorial
- DateTime FormatMask
- NxPreview Quick Start
- 32bit Bitmaps Tutorial
- Quick update
- Enable typing unicode characters in InplaceEditors
- Using NxColorScheme
- NxProgress Tutorial
- NxAutoCompletion Tutorial
Labs
NextGrid .NET
NxVirtualDataSet tutorial
Related Articles:
Info
- Skill:
- Version: 1.0.0
- Author: Bojan Nikolic
- Created: 2008-11-21
- Updated: 2009-02-28
Downloads
Because of this virtualization it is possible to use the TNxVirtualDatSet to turn almost anything rectangular (like a TCollection or a TStringList) into a DataSet. It is also possible to turn hardware into a database (like values from an usb thermometer or a joystick). Computed fields are also easy to implement (like the length of a line in a TStringList).
Virtualized are the following parts of the TDataSet:
Part | Event |
---|---|
Number of fields | OnFieldCount event |
Field definitions | OnAddField event |
Number of records | OnRecordCount event |
Reading Field values | OnGetFieldData / OnGetBlobData events |
Writing Field values | OnSetFieldData / OnSetFieldMode events |
Request for data for these virtualized parts are peformed through a number of events.
Normally the first event handler called is the number of fields, after which TNxVirtualDataSet needs the definition of each field.
Shortly afterwards TnxVirtualDataSet will need the number of records. Then TnxVirtualDataSet starts making numerous requests for field values at a high pace. Efficient coding of this event is required as it is used when visual Db Controls are repainted.
Write support is experimental and a bit tricky. After an Append, Edit or Insert call to TNxVirtualDataSet the OnSetFieldData event is used to signal modification to field data. The program must cache this field data as it is not clear at that moment what operation will be performed on which record.
When the programm calls the Post, Cancel or Delete method, the OnSetFieldMode event is called with a set of UpdateModes. Normally it is a combination of umAppend, umEdit or umInsert and umPost. Depending on the presence of umAppend, umEdit or umInsert the programmer must add, change or insert a new record in the underlying storage. As parameters of the OnSetFieldMode event, TnxVirtualDataSet passes the recordnumber of the involved record.
Not combined with other values are the UpdateModes umDelete and umCancel. On encountering umDelete, the program must delete the involved. The last mode, umCancel simply means ignoring the previously changed data.
The demo application uses a TStringList to store lines of text. Each line represents a single record. The TNextDbGrid displays the followind data:
Field 0 the index of the line
Field 1 the text of the line
Field 2 the length of the line
Figure 1. Appending a record to the TNxVirtualDataSet.
function TForm1.NxVirtualDataSet1GetFieldData(Sender: TObject; const rowIndex, fieldIndex: Integer): OLEVariant; begin case fieldIndex of 0: Result := NxVirtualDataSet1.RecNo; 1: if Assigned(fStorage) and (rowIndex >= 0) and (rowIndex < fStorage.Count) then Result := fStorage[rowIndex] else Result := '**Error**'; 2: if Assigned(fStorage) and (rowIndex >= 0) and (rowIndex < fStorage.Count) then Result := Length(fStorage[rowIndex]) else Result := '-1'; end; end; end;