In my previous blog post I went over some of the performance benefits of the new “Server Mode” feature for the VCL grid from DevExpress. In this brief post, I’ll go over the steps needed to get started using this new feature. In this example I’ll be targeting Microsoft SQL Server using ADO.
You’ll want to start off by creating a new VCL Forms Application. Add a TcxGrid control to the form. Right-click the default grid level to invoke the level’s context menu. From there, create a new Server Mode grid view.
Next, drop a TADOConnection component on the form. It can be found in the dbGo section of the Tool Palette, or by using he Search box.
With the TADOConnection component selected, configure it by setting LoginPrompt to False and clicking the elipsis next to ConnectionString to configure the underlying connection.
As I mentioned, in this example I’m targeting Microsoft SQL Server. The project source linked at the end of the blog post contains SQL scripts for creating a sample table and filling it with data. Use the Data Link Properties dialog to configure the connection.
With the connection configured, locate the TdxServerModeADODataSource on the tool palette and drop it on the form. The “Server Mode” datasource is responsible for taking the needs of the TcxGrid view and creating SQL queries that return only the data necessary to render the results on-screen.
The data source only has a few properties. Start off by setting Options.SQLAdapter to “MSSQL Adapter”. If you don’t set the Options.SQLAdapter, trying to configure other properties will let you know you’ll need to assign that property first. Next, set the Connection, after which you can use the drop down lists to select your TableName and KeyFieldNames.
With the datasource setup, we’re in the home stretch. Select the “Server Mode” view by clicking the “cxGrid1ServerModeTableView1” UI element on the TcxGrid control. With the view selected, expand the DataController node in the Object Inspector and assign the DataSource property.
Right-click the “cxGrid1ServerModeTableView1” UI element on the TcxGrid control and click “Create Missing Columns” to have the grid automatically create the columns found in the underlying data.
And that’s it! Running the application will leave you with a “blazing-fast” grid capable of loading, sorting, grouping, and filtering millions of rows of data.
You can download the Delphi source code and SQL scripts here.