阅读:1461回复:0
Delphi Example of an ODBC Dataset
procedure TMapForm.ODBCButtonClick(Sender: TObject);
var ds: Dataset; parm: Variant; fields: CMapXFields; begin try { CreateOleObject is found in the 'ComObj' package } parm := CreateOleObject('MapX.ODBCQueryInfo.4'); parm.SqlQuery := 'select * from USA'; { if the ConnectString is left blank, the user will be prompted to find a driver and data source. This can include uid=, pwd=, and dlg= fields. Change the DBQ= line if MapX was installed in another location. } parm.ConnectString := 'ODBC;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Program Files\MapInfo\MapX 5.0\Data\MapStats.mdb;'; { Rather than providing connection information in the connect string, a named data source can be created in the ODBC Data Sources Control Panel and used here. } parm.DataSource := ''; { Describe the structure of the Database. Here, we only bring in the 3 fields that we need. } fields := CoFields.Create; fields.Add('GEOABBR', 'GEOABBR', miAggregationAuto, miTypeString); fields.Add('GEONAME', 'GEONAME', miAggregationAuto, miTypeString); fields.Add('TOTPOP', 'TOTPOP', miAggregationAuto, miTypeNumeric); { Add the Dataset. } ds := Map1.Datasets.Add(miDataSetODBC, parm, 'ODBC Dataset',EmptyParam, EmptyParam, 'USA', fields, EmptyParam); { Create the default theme on the dataset. This will be a ranged theme on the TOTPOP field. } ds.Themes.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam); except on E: EOleException do Application.MessageBox(PChar(E.Message), 'Error', MB_OK or MB_ICONERROR); end; end; |
|
|