HOW TO
The following Delphi5 code sample demonstrates how to use AddRelate, with DAO syntax, on a DBF table.
This sample can also be used for Delphi4. Refer to the MapObjects Online Help topics 'accessing data', AddRelate, Table, and Database for more details.
Code:
var
dc : IMoDataConnection;
lys : IMoLayers;
lyr : IMoMapLayer;
tbl: IMoTable;
recs: IMoRecordset;
bool : Boolean;
begin
dc := IMoDataConnection(CreateOleObject('MapObjects2.DataConnection'));
dc.Database := GetCurrentDir;
lyr := IMoMapLayer(CreateOleObject('MapObjects2.MapLayer'));
lyr.GeoDataset := dc.FindGeoDataset('states');
lys := Map1.Layers;
lys.Add(lyr);
tbl := IMoTable(CreateOleObject('MapObjects2.Table'));
// Configure the driver using the ODBC Administrator
// in Control Panel
//tbl.Database := 'TestDSN';
tbl.Database := 'dBASE IV;DATABASE=' + GetCurrentDir;
tbl.Name := 'tab60211';
// User and Password properties are database dependent
// tbl.User :=
// tbl.Password :=
// Introduce some error checking to determine
// whether the application found the table.
recs := tbl.Records;
if recs.EOF then
begin
ShowMessage('No records in table ... exiting');
Exit;
end
else
ShowMessage('found table');
// Review the MapObjects2 Help for AddRelate
// in particular, you may want to experiment with
// the checkFields argument.
bool := lyr.AddRelate('state_abbr', tbl, 'state_abbr', False);
if bool then
ShowMessage('Successful')
else
ShowMessage('Failed');
end;
Navigate to your MapObjects\Samples\Delphi folder for additional Delphi sample code and tutorial, or download an updated Delphi tutorial from the MapObjects Developer Connection link found in the Related section.
Get help from ArcGIS experts
Download the Esri Support App