W
wangwei1
Unregistered / Unconfirmed
GUEST, unregistred user!
我用mo+delphi编写小的gis应用。
以下代码目的是通过外部的odbc:mp来关联shp文件,并高亮度显示制定的目标。
但首次运行,总提示程序错误框:access violation at address ××××× in module 。。。
不知到是否是某个对象应用错误。还是。。。。
请大家帮忙看看,谢谢!!!
procedure TForm1.Button1Click(Sender: TObject);
var
mylyr:Imomaplayer;
reltbl:IMoTable;
recs:IMORecordset;
count:integer;
field:IMofield;
value:string;
shp:iMoPolygon;
exp:string;
//rect:imorectangle;
dc:imodataconnection;
begin
dc:=imodataconnection(createoleobject('mapobjects2.dataconnection'));
dc.database:=samp1.returndatapath('world');
if not dc.connect then
exit;
mylyr:=imomaplayer(createoleobject('mapobjects2.maplayer'));
mylyr.geodataset:=dc.findgeodataset('ah');
map1.layers.add(mylyr);
//reltbl:=imotable(createoleobject('mapobjects2.table'));
reltbl:=cotable.Create as IMotable;
reltbl.Database:='mp';
reltbl.Name:='ah11.DBF';
// mylyr:=imomaplayer(createoleobject('mapobjects2.maplayer'));
mylyr:=map1.Layers.Item(0) as IMomaplayer
if mylyr.AddRelate('COUNTLL_ID',reltbl,'lx',true) then
begin
memo1.Clear;
showmessage('connect suss');
end
else
showmessage('connect error!');
recs:=mylyr.Records;
count:=recs.Count;
////////show results
while count > 0do
begin
field:=recs.Fields.Item('lx');
value:=field.ValueAsString;
recs.MoveNext;
memo1.Lines.Add(value);
count:=count-1;
end;
exp:='lx='''+'嗜人按蚊 '+'''';
wset:=mylyr.searchexpression(exp);
{if (not wset.eof) then
begin
flds:=wset.fields;
shp:=imopolygon(createoleobject('mapobjects2.polygon'));
shp:=Imopolygon(Idispatch(flds.item('shape').value));
rect:=imorectangle(createoleobject('mapobjects2.rectangle'));
//rect:=shp.extent;
//rect.scalerectangle((2.0));
// map1.extent:=rect;
map1.Refresh;
map1.flashshape(shp,20);
end
else
}
map1.Refresh;
end;
procedure TForm1.Map1AfterLayerDraw(Sender: TObject;
index: Smallint;
canceled: WordBool;
hDC: Cardinal);
var
shp1:iMoPolygon;
Symbol:imoSymbol;
flds:imofields;
FLD:imofield;
begin
Symbol:=imoSymbol(createoleobject('mapobjects2.Symbol'));
Symbol.COLOR:=clred;
FLDS:=wset.FIELDS;
FLD:=FLDS.ITEM('SHAPE');
SHP1:=Imopolygon(Idispatch(fld.value));
map1.drawshape(shp1,symbol);
SHP1:=NIL;
end;
以下代码目的是通过外部的odbc:mp来关联shp文件,并高亮度显示制定的目标。
但首次运行,总提示程序错误框:access violation at address ××××× in module 。。。
不知到是否是某个对象应用错误。还是。。。。
请大家帮忙看看,谢谢!!!
procedure TForm1.Button1Click(Sender: TObject);
var
mylyr:Imomaplayer;
reltbl:IMoTable;
recs:IMORecordset;
count:integer;
field:IMofield;
value:string;
shp:iMoPolygon;
exp:string;
//rect:imorectangle;
dc:imodataconnection;
begin
dc:=imodataconnection(createoleobject('mapobjects2.dataconnection'));
dc.database:=samp1.returndatapath('world');
if not dc.connect then
exit;
mylyr:=imomaplayer(createoleobject('mapobjects2.maplayer'));
mylyr.geodataset:=dc.findgeodataset('ah');
map1.layers.add(mylyr);
//reltbl:=imotable(createoleobject('mapobjects2.table'));
reltbl:=cotable.Create as IMotable;
reltbl.Database:='mp';
reltbl.Name:='ah11.DBF';
// mylyr:=imomaplayer(createoleobject('mapobjects2.maplayer'));
mylyr:=map1.Layers.Item(0) as IMomaplayer
if mylyr.AddRelate('COUNTLL_ID',reltbl,'lx',true) then
begin
memo1.Clear;
showmessage('connect suss');
end
else
showmessage('connect error!');
recs:=mylyr.Records;
count:=recs.Count;
////////show results
while count > 0do
begin
field:=recs.Fields.Item('lx');
value:=field.ValueAsString;
recs.MoveNext;
memo1.Lines.Add(value);
count:=count-1;
end;
exp:='lx='''+'嗜人按蚊 '+'''';
wset:=mylyr.searchexpression(exp);
{if (not wset.eof) then
begin
flds:=wset.fields;
shp:=imopolygon(createoleobject('mapobjects2.polygon'));
shp:=Imopolygon(Idispatch(flds.item('shape').value));
rect:=imorectangle(createoleobject('mapobjects2.rectangle'));
//rect:=shp.extent;
//rect.scalerectangle((2.0));
// map1.extent:=rect;
map1.Refresh;
map1.flashshape(shp,20);
end
else
}
map1.Refresh;
end;
procedure TForm1.Map1AfterLayerDraw(Sender: TObject;
index: Smallint;
canceled: WordBool;
hDC: Cardinal);
var
shp1:iMoPolygon;
Symbol:imoSymbol;
flds:imofields;
FLD:imofield;
begin
Symbol:=imoSymbol(createoleobject('mapobjects2.Symbol'));
Symbol.COLOR:=clred;
FLDS:=wset.FIELDS;
FLD:=FLDS.ITEM('SHAPE');
SHP1:=Imopolygon(Idispatch(fld.value));
map1.drawshape(shp1,symbol);
SHP1:=NIL;
end;