Link to continue :)
Saved map of DelphiCode:
VaR mapdoc: imapdocument; // remove the mydoc defined in private
Begin
Mapdoc: = comapdocument. Create as imapdocument;
Mapdoc. Open (mapctl1.documentfilename ,'');
If mapdoc. isreadonly [mapctl1.documentfilename] = false then
Begin
Mapdoc. replacecontents (mapctl1.map as imxdcontents );
Mapdoc. Save (mapdoc. usesrelativepaths, false );
// Close the mapdocument
Mapdoc. Close ();
End
Else
Application. MessageBox ('file read-only, saving failed! ',' Warning ');
End;
Due to the setting of the Delphi code editor, soft carriage return will be ineffective here. The viewer can pay attention to it.
Here, we will focus on the need to copy a copy of mapcontrol in many versions on the Internet. Otherwise, some elements will not be stored and I have not tried these. If so, it will be mentioned later.
A lite version of ArcMap should start with some special marking or customization on the existing map, and this project I am working on is no exception. Therefore, I paid a lot of effort to study the Manual (three: arccatalog and ArcMap operations and production), and sorted out the following programming steps: adding specific layers, making custom symbols, and tagging.
Add layers: There are a lot of classes involved. Many classes look at their heads, but they are still quite clear. Put the code first.
I first created a shape file and then loaded it to the open map.
Procedure createshpfile (DIR {folder}, filename {file name}: string; spatialrefer: ispatialreference {coordinate projection });
VaR aworkspacefactory: iworkspacefactory; afeatureworkspace: ifeatureworkspace; afields: ifields; region: region; afield: ifield; afieldedt: region; ageodef: role; Role: role; aunknowncsys: Role; begin if fileexists (DIR + filename) Then deletefile (DIR + filename); aworkspacefactory: = coshapefileworkspacefactory. create as iworkspacefactory; afeatureworkspace: = aworkspacefactory. openfromfile (Dir, 0) as ifeatureworkspace; afields: = cofields. create as ifields; afieldsedt: = afields as ifieldsedit; afield: = cofield. create as ifield; afieldedt: = afield as ifieldedit; afieldedt. name: = 'shape'; afieldedt. type _: = esrifieldtypegeometry; ageodef: = cogeometrydef. create as igeometrydef; ageodefedt: = ageodef as igeometrydefedit; ageodefedt. geometrytype: = esrigeometrypoint; // ageodefedt. _ set_spatialreference (spatialrefer); // aunknowncsys: = counknowncoordinatesystem. create as iunknowncoordinatesystem; // ageodefedt. _ set_spatialreference (aunknowncsys); // a function createspatialreference is omitted. You can use this function to customize your own space. Refer to afieldedt. _ set_geometrydef (ageodef); afieldsedt. addfield (afield); afeatureworkspace. createfeatureclass (filename, afields, nil, nil, esriftsimple, 'shape ','');
End;
The above code can be easily understood by those who have used AE. If there are old cainiao like me, let's listen to them.
Workspacefactory = workshop (workspace) => device (fields/field/geometrydef) => product positioning (spatialreference) = create)
As I wrote earlier, it was customized in the case of an existing map, and no other parameters were involved here, so the existing space parameters were used during the call:
VaR
Dir: string; FN: string; begin dir: = extractfilepath (mapctl1.documentfilename); FN: = 'test. shp'; createshpfile (Dir, FN, mapctl1.defainterface interface. spatialreference );
Mapctl1.defaultinterface. addshapefile (Dir, FN); // mapctl1 is mapcontrol
Interested comrades can go to ESRI ChinaCommunityCheck how to define spatial parameters.
At this point, I have some experiences in developing AE in Delphi:
1. The variable settings are basically interfaces: ilayer/icommand/iworkspacefactory/ifield ....
All classes with CO headers are used for Array creation and converted
2. If an interface is red, or the code written by the predecessors cannot be compiled, the result of the corresponding unit is basically not referenced. Use library locator to find its home and add it to uses.
3. when performing forced conversion with as, if such an error is reported, the conversion type is usually not allowed. Use the EO browser tool to find the corresponding class, check the supported interfaces, and then troubleshoot the error.
4. Be good at using the defaultinterface interface of mapcontrol. All the attributes not included in Delphi supported by other languages should be added.
5. there is also a common problem in Delphi, which is also the biggest difference from other languages, that is, many other languages support the attribute of direct assignment to Delphi and become read-only, such as map in mapcontrol, geometrydefedit spatialreference and so on. The solution is to first look for methods like _ set, as shown in the code above. In addition, let's see if there are any derived interfaces, such as defaultinterface. If you find it, Congratulations :) There is another stream holding the stone.
Today is the time to go here. You are welcome to join us with some tips developed by Delphi to enrich your life and enjoy unlimited fun.