unit M2Addon;

interface

uses
	Windows, ActiveX;

{****************************************************************

	IM2* - интерфейс
	TM2* - помощник для доступа к интерфейсу (object с OleObject'ом)

	TM2Custom* - базовый класс для реализации IM2* 
	IM2*Imp - диспетчер методов интерфейса к методам базового класса

 ****************************************************************}

const
	kSDKVersion = $0104;

	kNoID = '';

	{Сообщения от ГИС к AddOns - TM2Notify, TM2AddOnOptions}
	advProjectOpened = $0001;
	advProjectClosing = $0002;
	advProjectAttrsChanged = $0004;
	advProjectContentsChanged = $0008;
	advMapObjectSelected = $0010;
	advMapObjectDeselected = $0020;
	advMapObjectAdded = $0040;
	advMapObjectDeleted = $0080;
	advMapObjectModified = $0100;
	advGisInitialized = $0200;
	advGisUninitializing = $0400;

	{Параметры передаваемые в IM2ParamsList}
	kndProject = 1;
	kndMap = 2;
	kndLayer = 3;
	kndMapObject = 4;
	kndShape = 5;

	{Типы карт}
	kmtRaster = 2;
	kmtVect = 3;

	{Команды рисования контура}
	ccNone = 0;
	ccMoveTo = 1;
	ccLineTo = 2;
	ccArcTo = 3;
	ccCloseByLine = 4;
	ccCloseByArc = 5;

	{Клавиши мыши}
	kmbLeft = 0;
	kmbRight = 1;
	kmbMiddle = 2;

	{Состояния клавиатуры и мыши}
	kssShift = $01;
	kssAlt = $02;
	kssCtrl = $04;
	kssLeft = $08;
	kssRight = $10;
	kssMiddle = $20;
	kssDouble = $40;

	{Фаза обработки события в окне карты}
	phsNoProcess = 0;
	phsAlways = 1;
	phsCapture = 2;
	phsPreProcess = 3;
	phsProcess = 4;

	{Флаги редактора карты - TM2EditorOptions}
	eopAlwaysPhase = $01;
	eopPreProcessPhase = $02;
	eopProcessPhase = $04;

	eopMouseDown = $10;
	eopMouseMove = $20;
	eopMouseUp = $40;
	eopKeyDown = $80;
	eopKeyUp = $100;

	eopContextMenu = $200;
	eopDragging = $400;
	eopNotification = $800;
	eopPaint = $1000;

	{Коды оповещения редактора карты}
	enfInserted = 0;
	enfRemoving = 1;
	enfRemoved = 2;
	enfViewChanged = 3;

	{Флаги состояния меню}
	mnsDisabled = 1;
	mnsChecked = 2;

	{Флаги состояния handles}
	khsNormal = 0;
	khsHollow = 1;
	khsSelected = 2;

	{Стили карандаша}
	kpsSolid = 0;
	kpsDash = 1;
	kpsDot = 2;
	kpsDashDot = 3;
	kpsDashDotDot = 4;
	kpsClear = 5;
	kpsInsideFrame = 6;

	{Стили кисти}
	kbsSolid = 0;
	kbsClear = 1;
	kbsHorizontal = 2;
	kbsVertical = 3;
	kbsFDiagonal = 4;
	kbsBDiagonal = 5;
	kbsCross = 6;
	kbsDiagCross = 7;

	{Стили шрифта}
	kfsPlane = $00;
	kfsBold = $01;
	kfsItalic = $02;
	kfsUnderline = $04;
	kfsStrikeOut = $08;

	{Шаг шрифта}
	kfpDefault = 0;
	kfpVariable = 1;
	kfpFixed = 2;

	{Методы отображения - TM2PainterType}
	kptSimple = 0;
	kptText = 1;
	kptSymbol = 2;

	{Стили рисования символов - TM2SymbolPaintMethod}
	kspSingle = 0;
	kspOutline = 1;
	kspFill = 2;
	kspVertexIn = 3;
	kspVertexOut = 4;
	kspVertexFirst = 5;
	kspVertexLast = 6;
	kspRect = 7;
	kspArrow = 8;

	{Флаги стиля - TM2StyleFlags}
	ksfDefineGeometry = $01;
	ksfExcludeFromCreateObjectMenu = $02;
	ksfExcludeFromAddShapeMenu = $04;
	ksfExcludeFromChangeStyleMenu = $08;

	{Флаги создания контура - TM2ContourCreationFlags}

	{Способы рисования контура при создании объекта - TM2ContourCreationType}
	kccLine = 0;
	kccArc = 1;
	kccMove = 2;

	{Тип связи семантической таблицы к слою}
	kltOneToOne = 0;
	kltOneToMany = 1;

	{Коды операций пространственной алгебры - TM2ContourOperation}
	kcoOr = 0;
	kcoAnd = 1;
	kcoSub = 2;
	kcoXor = 3;

	{Коды отношений контуров - TM2ContourRelation}
	kcrNone = 0;
	kcrContains = 1;
	kcrIntersects = 2;
	kcrTouches = 3;

	{Коды ветвей в системе предпочтений - TM2PrefRoot}
	kprGlobal = 0;
	kprUser = 1;
	kprProject = 2;
	kprUserProject = 3;

	{Цели вызова callback-функций - TM2CallbackPurpose}
	kcpBegin = 0;
	kcpProcess = 1;
	kcpEnd = 2;

type
	PM2ID = ^TM2ID;
	TM2ID = string[15];
	TM2Name = string[31];
	TM2MacroName = string[31];
	TM2Hint = string[63];
	TM2MenuPath = string[63];
	TM2String = string[255];
	TM2ShortCut = Longint;
	TM2Notify = Longint;
	TM2HandlerState = Longint;

	PM2Point = ^TM2Point;
	TM2Point = packed record
		X, Y: Double;
	end;

	PM2Rect = ^TM2Rect;
	TM2Rect = packed record
		X1, Y1, X2, Y2: Double;
	end;

	TM2Color = Longint;
	TM2PenStyle = Longint;
	TM2BrushStyle = Longint;
	TM2FontStyles = Longint;
	TM2FontPitch = Longint;
	TM2FontName = string[63];

	PM2Pen = ^TM2Pen;
	TM2Pen = packed record
		Style: TM2PenStyle;
		WidthInMM: Double;
		ForZoomScale: Double;
		Color: TM2Color;
	end;

	PM2Brush = ^TM2Brush;
	TM2Brush = packed record
		Style: TM2BrushStyle;
		BackColor: TM2Color;
		HatchColor: TM2Color;
		HollowBack: BOOL;
	end;

	PM2Font = ^TM2Font;
	TM2Font = packed record
		Name: TM2FontName;
		Style: TM2FontStyles;
		Color: TM2Color;
		Size: Longint;
		ForZoomScale: Double;
		Pitch: TM2FontPitch;
		CharSet: Longint;
	end;

	TM2AreaName = string[63];

	PM2AreaAttrs = ^TM2AreaAttrs;
	TM2AreaAttrs = packed record
		Name: TM2AreaName;
		Bounds: TM2Rect;
    NorthAngle: Double;
	end;

	TM2ProjectName = string[127];

	PM2ProjectAttrs = ^TM2ProjectAttrs;
	TM2ProjectAttrs = packed record
		Name: TM2ProjectName;
		AreaID: TM2ID;
	end;

	TM2MapName = string[63];

	PM2MapAttrs = ^TM2MapAttrs;
	TM2MapAttrs = packed record
		AreaID: TM2ID;
		Name: TM2MapName;
		MapType: Longint;
		VisibleMin, VisibleMax: Double;
	end;

	TM2LayerName = string[127];

	PM2LayerAttrs = ^TM2LayerAttrs;
	TM2LayerAttrs = packed record
		MapID: TM2ID;
		Name: TM2LayerName;
		VisibleMin, VisibleMax: Double;
	end;

	TM2AddOnOptions = Longint;

	PM2AddOnAttrs = ^TM2AddOnAttrs;
	TM2AddOnAttrs = packed record
		ClsID: TCLSID; {CLSID AddOn. Уникальный среди всех AddOns}
		Name: TM2Name; {Имя AddOn. Читабельное наименование}
		Hint: TM2Hint; {Описание AddOn (для чего он предназначен)}
		Options: TM2AddOnOptions; {Фильтры на сообщения, которые идут к расширению}
		SDKVersion: Longint; {На какой версии SDK сделан AddOn}
	end;

	PM2MacroAttrs = ^TM2MacroAttrs;
	TM2MacroAttrs = packed record
		Command: Longint;
		Name: TM2MacroName;
		Hint: TM2Hint;
		MenuPath: TM2MenuPath;
		MenuShortCut: TM2ShortCut;
		ToolbarName: TM2Name;
		ToolbarGroup: TM2Name;
		Bitmap: Longint;
	end;

	TM2MenuState = Longint;

	PM2ContextMacroAttrs = ^TM2ContextMacroAttrs;
	TM2ContextMacroAttrs = packed record
		Command: Longint;
		Name: TM2MacroName;
		Hint: TM2Hint;
		Path: TM2MenuPath;
		ShortCut: TM2ShortCut;
		State: TM2MenuState;
	end;

	TM2ContourCommandType = Longint;

	PM2ContourCommand = ^TM2ContourCommand;
	TM2ContourCommand = packed record
		CommandType: TM2ContourCommandType;
		case TM2ContourCommandType of
			ccNone:();
			ccMoveTo: (MoveTo: packed record Point: TM2Point end);
			ccLineTo: (LineTo: packed record Point: TM2Point end);
			ccArcTo: (ArcTo: packed record Point: TM2Point; Convexity: Double end);
			ccCloseByLine: ();
			ccCloseByArc: (CloseByArc: packed record Convexity: Double end);
	end;

	//Forwards
	IM2GISDatabase = interface;
	IM2MapProject = interface;
	IM2MapObjects = interface;
	IM2MapView = interface;
	IM2GeometryLib = interface;
	IM2Preferences = interface;
	IM2Callback = interface;

	IM2IDsList = interface(IUnknown)
		['{C8F84441-1878-11D0-9DF1-444553540000}']
		function i_GetItem(i: Longint; out anItem: TM2ID): HResult; stdcall;
		function i_GetCount(out aCount: Longint): HResult; stdcall;

		function i_Add(i: Longint; const anItem: TM2ID): HResult; stdcall;
		function i_Change(i: Longint; const anItem: TM2ID): HResult; stdcall;
		function i_Delete(i: Longint): HResult; stdcall;
		function i_Clear: HResult; stdcall;
	end;

	TM2IDsList = object
		OleObject: IM2IDsList;
		Dummy: Longint;

		function Items(i: Longint): TM2ID;
		function Count: Longint;

		procedure Add(const anItem: TM2ID);
		procedure Insert(i: Longint; const anItem: TM2ID);
		procedure Change(i: Longint; const anItem: TM2ID);
		procedure Delete(i: Longint);
		procedure Clear;

//		property Count: Longint read GetCount;
//		property Items[i: Longint]: TM2ID read GetItem; default;
	end;

	PIM2Contour = ^IM2Contour;
	IM2Contour = interface(IUnknown)
		['{C8F84451-1878-11D0-9DF1-444553540000}']
		function i_Clear: HResult; stdcall;

		function i_GetFirstCommand(out aCommand: TM2ContourCommand): HResult; stdcall;
		function i_GetNextCommand(out aCommand: TM2ContourCommand): HResult; stdcall;

		function i_AddCommand(const aCommand: TM2ContourCommand): HResult; stdcall;
		function i_InsertCommand(aBefore: Longint; const aCommand: TM2ContourCommand): HResult; stdcall;
		function i_SetCommand(anIndex: Longint; const aCommand: TM2ContourCommand): HResult; stdcall;
		function i_DeleteCommand(anIndex: Longint): HResult; stdcall;

		function i_GetCommand(AnIndex: Longint; out ACommand: TM2ContourCommand): HResult; stdcall;
		function i_GetCount(out ACount: Longint): HResult; stdcall;

		function i_Clone(out aContour: IM2Contour): HResult; stdcall;
	end;

	TM2Contour = object
		OleObject: IM2Contour;
		Dummy: Longint;

		procedure Clear;

		function GetFirstCommand(out aCommand: TM2ContourCommand): Boolean;
		function GetNextCommand(out aCommand: TM2ContourCommand): Boolean;

		procedure AddCommand(const aCommand: TM2ContourCommand);
		procedure InsertCommand(aBefore: Longint; const aCommand: TM2ContourCommand);
		procedure SetCommand(anIndex: Longint; const aCommand: TM2ContourCommand);
		procedure DeleteCommand(anIndex: Longint);

		procedure GetCommand(AnIndex: Longint; out ACommand: TM2ContourCommand);
		function Count: Longint;

		function Clone: IM2Contour;

//		property Count: Longint read GetCount;
	end;

	IM2ShapeList = interface(IUnknown)
		['{C8F84452-1878-11D0-9DF1-444553540000}']
		function i_Clear: HResult; stdcall;

		function i_Add(const aContour: IM2Contour; const aStyleID: TM2ID): HResult; stdcall;
		function i_Insert(aBefore: Longint; const aContour: IM2Contour; const aStyleID: TM2ID): HResult; stdcall;
		function i_Delete(anIndex: Longint): HResult; stdcall;

		function i_GetCount(out aCount: Longint): HResult; stdcall;
		function i_GetContour(anIndex: Longint; out aContour: IM2Contour): HResult; stdcall;
		function i_GetStyleID(anIndex: Longint; out aStyleID: TM2ID): HResult; stdcall;
		function i_SetStyleID(anIndex: Longint; const aStyleID: TM2ID): HResult; stdcall;
	end;

	TM2ShapeList = object
		OleObject: IM2ShapeList;
		Dummy: Longint;

		procedure Clear;

		procedure Add(const aContour: IM2Contour; const aStyleID: TM2ID);
		procedure Insert(aBefore: Longint; const aContour: IM2Contour; const aStyleID: TM2ID);
		procedure Delete(anIndex: Longint);

		function Count: Longint;
		function Contours(anIndex: Longint): IM2Contour;
		function StyleIDs(anIndex: Longint): TM2ID;
		procedure SetStyleID(anIndex: Longint; const aStyleID: TM2ID);

//		property Count: Longint read GetCount;
//		property Contours[anIndex: Longint]: IM2Contour read GetContour; default;
//		property StyleIDs[anIndex: Longint]: TM2ID read GetStyleID write SetStyleID;
	end;

	IM2ShapeListPrivate = interface(IM2ShapeList)
		['{C8F84552-1878-11D0-9DF1-444553540000}']
		function i_ModifyOwnObject(const anObjectID: TM2ID): HResult; stdcall;
	end;

	TM2ShapeListPrivate = object
		OleObject: IM2ShapeListPrivate;
		Dummy: Longint;

		function ModifyOwnObject(const anObjectID: TM2ID): Boolean;
	end;

	TM2PainterName = string[63];
	TM2PainterType = Longint;
	TM2SymbolPaintMethod = Longint;

	PM2PainterAttrs = ^TM2PainterAttrs;
	TM2PainterAttrs = packed record
		Name: TM2PainterName;
		VisibleMin, VisibleMax: double;
		Reserved: Longint;
		PainterType: TM2PainterType;
		case TM2PainterType of
			kptSimple:(Simple: packed record Pen: TM2Pen; Brush: TM2Brush; Reserved: Longint; end);
			kptText: (Text: packed record Text: TM2String; Font: TM2Font; Reserved: Longint; end);
			kptSymbol: (Symbol: packed record PaintMethod: TM2SymbolPaintMethod;
					Scale, StepValue: double; StepCount: Longint; Reserved: Longint; end);
	end;

	TM2StyleName = string[63];
	TM2StyleFlags = Longint;
	TM2ContourCreationFlags = Longint;
	TM2ContourCreationType = Longint;

	PM2StyleAttrs = ^TM2StyleAttrs;
	TM2StyleAttrs = packed record
		Name: TM2StyleName;
		Flags: TM2StyleFlags;
		CreationFlags: TM2ContourCreationFlags;
		BeginCreationType: TM2ContourCreationType;
		BeginOrtho: BOOL;
		EndCreationType: TM2ContourCreationType;
		EndOrtho: BOOL;
		MinPoints: Longint;
		MaxPoints: Longint;
		Reserved: Longint;
	end;

	IM2Style = interface(IUnknown)
		['{C8F84458-1878-11D0-9DF1-444553540000}']
		function i_GetID(out anID: TM2ID): HResult; stdcall;
		function i_GetLayerList(out aList: IM2IDsList): HResult; stdcall;
		function i_GetAttrs(out anAttrs: TM2StyleAttrs): HResult; stdcall;

		function i_GetPainterCount(out aCount: Longint): HResult; stdcall;
		function i_GetPainterAttrs(anIndex: Longint; out anAttrs: TM2PainterAttrs): HResult; stdcall;
		function i_AddPainter(anIndex: Longint; const anAttrs: TM2PainterAttrs): HResult; stdcall;
		function i_SetPainter(anIndex: Longint; const anAttrs: TM2PainterAttrs): HResult; stdcall;
		function i_DeletePainter(anIndex: Longint): HResult; stdcall;
	end;

	TM2Style = object
		OleObject: IM2Style;
		Dummy: Longint;
		
		function ID: TM2ID;
		function GetLayerList: IM2IDsList;
		procedure GetAttrs(out anAttrs: TM2StyleAttrs);

		function PainterCount: Longint;
		procedure GetPainterAttrs(anIndex: Longint; out anAttrs: TM2PainterAttrs);
		procedure AddPainter(const anAttrs: TM2PainterAttrs);
		procedure InsertPainter(anIndex: Longint; const anAttrs: TM2PainterAttrs);
		procedure SetPainter(anIndex: Longint; const anAttrs: TM2PainterAttrs);
		procedure DeletePainter(anIndex: Longint);

//		property ID: TM2ID read GetID;
//		property PainterCount: Longint read GetPainterCount;
	end;

	IM2IDsEnum = interface(IUnknown)
		['{C8F84440-1878-11D0-9DF1-444553540000}']
		function i_Next(out anID: TM2ID): HResult; stdcall;
		function i_Skip(aCount: Longint): HResult; stdcall;
		function i_Reset: HResult; stdcall;
	end;

	TM2IDsEnum = object
		OleObject: IM2IDsEnum;
		Dummy: Longint;
		
		function Next(out anID: TM2ID): Boolean;
		function Skip(aCount: Longint): Boolean;
		procedure Reset;
	end;

	IM2MacroAttrsList = interface(IUnknown)
		['{C8F84442-1878-11D0-9DF1-444553540000}']
		function i_GetItem(i: Longint; out AnItem: TM2MacroAttrs): HResult; stdcall;
		function i_GetCount(out ACount: Longint): HResult; stdcall;

		function i_Clear: HResult; stdcall;
		function i_Add(i: Longint; const anItem: TM2MacroAttrs): HResult; stdcall;
	end;

	TM2MacroAttrsList = object
		OleObject: IM2MacroAttrsList;
		Dummy: Longint;
		
		procedure GetItem(i: Longint; out AnItem: TM2MacroAttrs);
		function Count: Longint;

		procedure Clear;
		procedure Add(const anItem: TM2MacroAttrs);
		procedure Insert(i: Longint; const anItem: TM2MacroAttrs);

//		property Count: Longint read GetCount;
	end;

	IM2ParamsList = interface(IUnknown)
		['{C8F84443-1878-11D0-9DF1-444553540000}']
		function i_GetItem(AKey: Longint; out AnItem: TM2String): HResult; stdcall;
		function i_Contains(aKey: Longint): HResult; stdcall;

		function i_Clear: HResult; stdcall;
		function i_Add(aKey: Longint; const anItem: TM2String): HResult; stdcall;
	end;

	TM2ParamsList = object
		OleObject: IM2ParamsList;
		Dummy: Longint;

		function Items(AKey: Longint): TM2String;
		function Contains(aKey: Longint): Boolean;

		procedure Clear;
		procedure Add(aKey: Longint; const anItem: TM2String);

//		property Items[AKey: Longint]: TM2String read GetItem; default;
	end;

	IM2ContextMacroAttrsList = interface(IUnknown)
		['{C8F84444-1878-11D0-9DF1-444553540000}']
		function i_GetItem(i: Longint; out AnItem: TM2ContextMacroAttrs): HResult; stdcall;
		function i_GetCount(out ACount: Longint): HResult; stdcall;

		function i_Clear: HResult; stdcall;
		function i_Add(i: Longint; const anItem: TM2ContextMacroAttrs): HResult; stdcall;
	end;

	TM2ContextMacroAttrsList = object
		OleObject: IM2ContextMacroAttrsList;
		Dummy: Longint;
		
		procedure GetItem(i: Longint; out AnItem: TM2ContextMacroAttrs);
		function Count: Longint;
		
		procedure Clear;
		procedure Add(const anItem: TM2ContextMacroAttrs);
		procedure Insert(i: Longint; const anItem: TM2ContextMacroAttrs);

//		property Count: Longint read GetCount;
	end;

	PM2TopoLink = ^TM2TopoLink;
	TM2TopoLink = packed record
		Source: packed record
			Shape: Longint;
			P1, P2: Longint;
		end;
		Target: packed record
			ID: TM2ID;
			Shape: Longint;
			P1, P2: Longint;
		end;
	end;

	IM2TopoLinkList = interface(IUnknown)
		['{C8F84445-1878-11D0-9DF1-444553540000}']
		function i_GetItem(i: Longint; out anItem: TM2TopoLink): HResult; stdcall;
		function i_GetCount(out aCount: Longint): HResult; stdcall;
	end;

	TM2TopoLinkList = object
		OleObject: IM2TopoLinkList;
		Dummy: Longint;

		procedure GetItem(i: Longint; out anItem: TM2TopoLink);
		function Count: Longint;

//		property Count: Longint read GetCount;
	end;

	TM2MouseButton = Longint;
	TM2ShiftState = Longint;

	TM2ProcessPhase = Longint;
	TM2EditorOption = Longint;
	TM2EditorOptions = Longint;
	TM2EditorNotification = Longint;

	IM2Editor = interface(IUnknown)
		['{C8F84453-1878-11D0-9DF1-444553540000}']
		function i_GetEditorOptions(out AnOptions: TM2EditorOptions): HResult; stdcall;

		function i_HideDragging: HResult; stdcall;
		function i_ShowDragging(AMouse: TPoint): HResult; stdcall;

		function i_MouseDown(AButton: TM2MouseButton; AShift: TM2ShiftState; AMouse: TPoint): HResult; stdcall;
		function i_MouseMove(AShift: TM2ShiftState; AMouse: TPoint): HResult; stdcall;
		function i_MouseUp(AButton: TM2MouseButton; AShift: TM2ShiftState; AMouse: TPoint): HResult; stdcall;

		function i_KeyDown(AKey: Word; AShift: TM2ShiftState): HResult; stdcall;
		function i_KeyUp(AKey: Word; AShift: TM2ShiftState): HResult; stdcall;

		function i_Timer: HResult; stdcall;
		function i_Notification(AWhat: TM2EditorNotification): HResult; stdcall;

		function i_GetContextMacroList(out AList: IM2ContextMacroAttrsList; AMouse: TPoint): HResult; stdcall;
		function i_ExecuteMacro(ACommand: Longint; const AParams: TM2String): HResult; stdcall;

		function i_Cancel: HResult; stdcall;
		function i_Paint: HResult; stdcall;
	end;

	TM2Editor = object
		OleObject: IM2Editor;
		Dummy: Longint;

		function GetEditorOptions: TM2EditorOptions;

		procedure HideDragging;
		procedure ShowDragging(AMouse: TPoint);

		procedure MouseDown(AButton: TM2MouseButton; AShift: TM2ShiftState; AMouse: TPoint);
		procedure MouseMove(AShift: TM2ShiftState; AMouse: TPoint);
		procedure MouseUp(AButton: TM2MouseButton; AShift: TM2ShiftState; AMouse: TPoint);

		procedure KeyDown(Key: Word; AShift: TM2ShiftState);
		procedure KeyUp(Key: Word; AShift: TM2ShiftState);

		procedure Timer;
		procedure Notification(AWhat: TM2EditorNotification);

		function GetContextMacroList(AMouse: TPoint): IM2ContextMacroAttrsList;
		procedure ExecuteMacro(ACommand: Longint; const AParams: TM2String);

		procedure Cancel;
		procedure Paint;
	end;

	IM2Application = interface(IDispatch)
		['{C8F84410-1878-11D0-9DF1-444553540000}']
		function i_GetApplication(out retval: IM2Application): HResult; stdcall;
		function i_GetCaption(out retval: WideString): HResult; stdcall;
		function i_GetFullName(out retval: WideString): HResult; stdcall;
		function i_GetPath(out retval: WideString): HResult; stdcall;
		function i_GetName(out retval: WideString): HResult; stdcall;
		function i_GetParent(out retval: IM2Application): HResult; stdcall;
		function i_Quit: HResult; stdcall;
	end;

	TM2Application = object
		OleObject: IM2Application;
		Dummy: Longint;
		
		function Application: IM2Application;
		function Caption: string;
		function FullName: string;
		function Path: string;
		function Name: string;
		function Parent: IM2Application;
		procedure Quit;

//		property Application: IM2Application read GetApplication;
//		property Caption: string read GetCaption;
//		property FullName: string read GetFullName;
//		property Path: string read GetPath;
//		property Name: string read GetName;
//		property Parent: IM2Application read GetParent;
	end;

	IM2AddOnManager = interface(IUnknown)
		['{C8F84411-1878-11D0-9DF1-444553540000}']
		function i_GetMainWindow(out AWnd: HWnd): HResult; stdcall;
		function i_GetAppDesktop(out AHandle: THandle): HResult; stdcall;
	end;

	TM2AddOnManager = object
		OleObject: IM2AddOnManager;
		Dummy: Longint;
		
		function GetMainWindow: HWnd;
		function GetAppDesktop: THandle;
	end;

	TM2TableName = string[63];

	PM2CreateTableAttrs = ^TM2CreateTableAttrs;
	TM2CreateTableAttrs = packed record
		OneToOne: BOOL;
		UserTableName: TM2TableName;
		TableDef: PChar;
	end;

	PM2TableAttrs = ^TM2TableAttrs;
	TM2TableAttrs = packed record
		OneToOne: BOOL;
		UserTableName: TM2TableName;
		TableName: TM2TableName;
	end;

	TM2UserName = string[63];

	PM2UserAttrs = ^TM2UserAttrs;
	TM2UserAttrs = packed record
		Name: TM2UserName;
	end;

	IM2GISDatabase = interface(IUnknown)
		['{C8F84412-1878-11D0-9DF1-444553540000}']
		function i_GetDatabaseName(out AName: TM2String): HResult; stdcall;
		function i_GetUniqueID(out AnID: TM2ID): HResult; stdcall;

		function i_GetAreaList(out AList: IM2IDsList): HResult; stdcall;
		function i_GetAreaAttrs(const AnID: TM2ID; out AnAttrs: TM2AreaAttrs): HResult; stdcall;
		function i_GetMapList(const AnAreaID: TM2ID; out AList: IM2IDsList): HResult; stdcall;
		function i_GetMapAttrs(const AnID: TM2ID; out AnAttrs: TM2MapAttrs): HResult; stdcall;
		function i_GetLayerList(const AMapID: TM2ID; out AList: IM2IDsList): HResult; stdcall;
		function i_GetLayerAttrs(const AnID: TM2ID; out AnAttrs: TM2LayerAttrs): HResult; stdcall;
		function i_GetStyleList(const ALayerID: TM2ID; out AList: IM2IDsList): HResult; stdcall;
		function i_GetStyle(const AnID: TM2ID; out AStyle: IM2Style): HResult; stdcall;

		function i_AddMap(const anAttrs: TM2MapAttrs; out aMapID: TM2ID): HResult; stdcall;
		function i_AddLayer(const anAttrs: TM2LayerAttrs; out aLayerID: TM2ID): HResult; stdcall;
		function i_AddStyle(const aLayerID: TM2ID; const anAttrs: TM2StyleAttrs; out aStyleID: TM2ID): HResult; stdcall;
		function i_AddTable(const aLayerID: TM2ID; const anAttrs: TM2CreateTableAttrs; out aTableID: TM2ID): HResult; stdcall;

		function i_GetDatabaseID(out anID: Longint): HResult; stdcall;

		function i_Dummy270597_1(aValue: Longint): HResult; stdcall;

		function i_GetCurrentUser(out anUserID: TM2ID): HResult; stdcall;
		function i_GetUserList(out aList: IM2IDsList): HResult; stdcall;
		function i_GetUserAttrs(const anUserID: TM2ID; out anAttrs: TM2UserAttrs): HResult; stdcall;

		function i_GetTableList(const aLayerID: TM2ID; out aList: IM2IDsList): HResult; stdcall;
		function i_GetTableAttrs(const aTableID: TM2ID; out anAttrs: TM2TableAttrs): HResult; stdcall;

		function i_GetAddonData(const aKey: TM2String; const aStm: IStream): HResult; stdcall;
		function i_SetAddonData(const aKey: TM2String; const aStm: IStream): HResult; stdcall;
	end;

	TM2GISDatabase = object
		OleObject: IM2GISDatabase;
		Dummy: Longint;

		function DatabaseName: TM2String;
		function GetUniqueID: TM2ID;

		function GetAreaList: IM2IDsList;
		procedure GetAreaAttrs(const AnID: TM2ID; out AnAttrs: TM2AreaAttrs);
		function GetMapList(const AnAreaID: TM2ID): IM2IDsList;
		procedure GetMapAttrs(const AnID: TM2ID; out AnAttrs: TM2MapAttrs);
		function GetLayerList(const AMapID: TM2ID): IM2IDsList;
		procedure GetLayerAttrs(const AnID: TM2ID; out AnAttrs: TM2LayerAttrs);
		function GetStyleList(const ALayerID: TM2ID): IM2IDsList;
		function GetStyle(const AnID: TM2ID): IM2Style;

		function AddMap(const anAttrs: TM2MapAttrs): TM2ID;
		function AddLayer(const anAttrs: TM2LayerAttrs): TM2ID;
		function AddStyle(const aLayerID: TM2ID; const anAttrs: TM2StyleAttrs): TM2ID;
		function AddTable(const aLayerID: TM2ID; const anAttrs: TM2CreateTableAttrs): TM2ID;

		function DatabaseID: Longint;

		function CurrentUser: TM2ID;
		function GetUserList: IM2IDsList;
		procedure GetUserAttrs(const anUserID: TM2ID; out anAttrs: TM2UserAttrs);

		function GetTableList(const aLayerID: TM2ID): IM2IDsList;
		procedure GetTableAttrs(const aTableID: TM2ID; out anAttrs: TM2TableAttrs);

		function GetAddonData(const aKey: TM2String; const aStm: IStream): Boolean;
		procedure SetAddonData(const aKey: TM2String; const aStm: IStream);

//		property DatabaseName: TM2String read GetDatabaseName;
//		property DatabaseID: Longint read GetDatabaseID;
//		property CurrentUser: TM2ID read GetCurrentUser;
	end;

	IM2MapProject = interface(IUnknown)
		['{C8F84413-1878-11D0-9DF1-444553540000}']
		function i_GetID(out AnID: TM2ID): HResult; stdcall;
		function i_GetAttrs(out AnAttrs: TM2ProjectAttrs): HResult; stdcall;

		function i_SetActiveMap(const AMapID: TM2ID): HResult; stdcall;
		function i_SetActiveLayer(const ALayerID: TM2ID): HResult; stdcall;
		function i_GetActiveMap(out AnID: TM2ID): HResult; stdcall;
		function i_GetActiveLayer(out AnID: TM2ID): HResult; stdcall;

		function i_AddMap(const aMapID: TM2ID): HResult; stdcall;
		function i_GetMapList(out aList: IM2IDsList): HResult; stdcall;
		function i_GetLayerList(const aMapID: TM2ID; out aList: IM2IDsList): HResult; stdcall;
	end;

	TM2MapProject = object
		OleObject: IM2MapProject;
		Dummy: Longint;
		
		function ID: TM2ID;
		procedure GetAttrs(out AnAttrs: TM2ProjectAttrs);

		procedure SetActiveMap(const AMapID: TM2ID);
		procedure SetActiveLayer(const ALayerID: TM2ID);
		function ActiveMap: TM2ID;
		function ActiveLayer: TM2ID;

		procedure AddMap(const aMapID: TM2ID);
		function GetMapList: IM2IDsList;
		function GetLayerList(const aMapID: TM2ID): IM2IDsList;

//		property ActiveMap: TM2ID read GetActiveMap write SetActiveMap;
//		property ActiveLayer: TM2ID read GetActiveLayer write SetActiveLayer;
	end;

	PM2Variant = ^TM2Variant;
	TM2Variant = packed record
		vt: Longint;
		case Integer of
			VT_I4:  	(lVal: Longint);
			VT_R8:   	(dblVal: Double);
			VT_CY: 		(cyVal: Currency);
			VT_DATE:  (dateVal: Double);
			VT_LPSTR: (strVal: PAnsiChar);
			VT_ERROR: (scode: HRESULT);
			VT_BOOL:  (boolVal: WordBool);
	end;                         
	PM2VariantArray = ^TM2VariantArray;
	TM2VariantArray = array [0..32000] of TM2Variant;

	PM2TableData = ^TM2TableData;
	TM2TableData = packed record
		TableID: TM2ID;
		FieldNames: PM2Variant;
		FieldCount: Longint;
		Data: PM2Variant;
		ElemCount: Longint;
	end;

	PM2ObjectData = ^TM2ObjectData;
	TM2ObjectData = packed record
		Data: PM2TableData;
		Count: Longint;
	end;

	IM2MapObjects = interface(IUnknown)
		['{C8F84414-1878-11D0-9DF1-444553540000}']
		function i_CreateContour(out aContour: IM2Contour): HResult; stdcall;
		function i_CreateShapeList(out aShapeList: IM2ShapeList): HResult; stdcall;

		function i_AddObject(const aLayerID: TM2ID; const aShapeList: IM2ShapeList; out anObjectID: TM2ID): HResult; stdcall;
		function i_GetObjectLayerID(const anObjectID: TM2ID; out aLayerID: TM2ID): HResult; stdcall;
		function i_GetObjectShapeList(const anObjectID: TM2ID; out aShapeList: IM2ShapeList): HResult; stdcall;
		function i_DeleteObject(const AnObjectID: TM2ID): HResult; stdcall;
		function i_ModifyObject(const AnObjectID: TM2ID; const AShapeList: IM2ShapeList): HResult; stdcall;

		function i_FindObjectAtPos(const ALayer: TM2ID; AnOnlyVisible: BOOL; const APoint: TM2Point;
				out AnObjectID: TM2ID; out AShapeIndex: Longint): HResult; stdcall;
		function i_FindIntersectedObjects(const ALayer: TM2ID; AnOnlyVisible: BOOL; const ARect: TM2Rect;
				AnOnlyEnclosed: BOOL; out AList: IM2IDsList): HResult; stdcall;

		function i_ObjectDataChanged(const AnObjectID: TM2ID): HResult; stdcall;

		function i_GetCenter(const APt1: TM2Point; const APt2: TM2Point; const APt: TM2Point;
				out ADelta: Double; out ACenter: TM2Point): HResult; stdcall;
		function i_GetCenter2(const APt1: TM2Point; const APt2: TM2Point; AConvexity: Double;
				out ADelta: Double; out ACenter: TM2Point): HResult; stdcall;
		function i_GetConvexity(const APt1: TM2Point; const APt2: TM2Point; const APt: TM2Point;
				out AConvexity: Double): HResult; stdcall;

		function i_BeginUpdate: HResult; stdcall;
		function i_EndUpdate: HResult; stdcall;

		function i_GetObjectsEnum(const aLayerID: TM2ID; out anEnum: IM2IDsEnum): HResult; stdcall;
		function i_GetObjectBounds(const anObjectID: TM2ID; out aBounds: TM2Rect): HResult; stdcall;
		function i_GetObjectData(const anObjectID: TM2ID; aFieldData: BOOL; out aData: TM2ObjectData): HResult; stdcall;
		function i_SetObjectData(const anObjectID: TM2ID; aFieldData: BOOL; const aData: TM2ObjectData): HResult; stdcall;

		function i_Undo(aCount: Longint): HResult; stdcall;

		function i_AddTopoLinks(const anID: TM2ID; const aList: IM2IDsList): HResult; stdcall;
		function i_DeleteTopoLinks(const anID: TM2ID; const aList: IM2IDsList): HResult; stdcall;
		function i_GetTopoLinks(const anID: TM2ID; out aList: IM2IDsList): HResult; stdcall;
		function i_GetTopoLinksInfo(const anID: TM2ID; const aList: IM2IDsList;
				out aTopoLinks: IM2TopoLinkList): HResult; stdcall;
		function i_FindTopoLinksInfo(const aContour: IM2Contour; aDistance: double; const aForLayer: TM2ID;
				const aRelLayers: IM2IDsList; out aTopoLinks: IM2TopoLinkList): HResult; stdcall;
	end;

	TM2MapObjects = object
		OleObject: IM2MapObjects;
		Dummy: Longint;
		
		function CreateContour: IM2Contour;
		function CreateShapeList: IM2ShapeList;

		function AddObject(const aLayerID: TM2ID; const aShapeList: IM2ShapeList): TM2ID;
		function GetObjectLayerID(const anObjectID: TM2ID): TM2ID;
		function GetObjectShapeList(const anObjectID: TM2ID): IM2ShapeList;
		procedure DeleteObject(const AnObjectID: TM2ID);
		procedure ModifyObject(const AnObjectID: TM2ID; const AShapeList: IM2ShapeList);

		function FindObjectAtPos(const ALayer: TM2ID; AnOnlyVisible: BOOL;
				const APoint: TM2Point; out AShapeIndex: Longint): TM2ID;
		function FindIntersectedObjects(const ALayer: TM2ID; AnOnlyVisible: BOOL; const ARect: TM2Rect;
				AnOnlyEnclosed: BOOL): IM2IDsList;

		procedure ObjectDataChanged(const AnObjectID: TM2ID);

		function GetCenter(const APt1: TM2Point; const APt2: TM2Point; const APt: TM2Point;
				out ADelta: Double): TM2Point;
		function GetCenter2(const APt1: TM2Point; const APt2: TM2Point; AConvexity: Double;
				out ADelta: Double): TM2Point;
		function GetConvexity(const APt1: TM2Point; const APt2: TM2Point; const APt: TM2Point): Double;

		procedure BeginUpdate;
		procedure EndUpdate;

		function GetObjectsEnum(const aLayerID: TM2ID): IM2IDsEnum;
		function GetObjectBounds(const anObjectID: TM2ID): TM2Rect;
		procedure GetObjectData(const anObjectID: TM2ID; aFieldData: Boolean; out aData: TM2ObjectData);
		procedure SetObjectData(const anObjectID: TM2ID; aFieldData: Boolean; const aData: TM2ObjectData);

		procedure Undo(aCount: Longint);

		procedure AddTopoLinks(const anID: TM2ID; const aList: IM2IDsList);
		procedure DeleteTopoLinks(const anID: TM2ID; const aList: IM2IDsList);
		function GetTopoLinks(const anID: TM2ID): IM2IDsList;
		function GetTopoLinksInfo(const anID: TM2ID; const aList: IM2IDsList): IM2TopoLinkList;
		function FindTopoLinksInfo(const aContour: IM2Contour; aDistance: double; const aForLayer: TM2ID;
				const aRelLayers: IM2IDsList): IM2TopoLinkList;
	end;

	IM2MapView = interface(IUnknown)
		['{C8F84415-1878-11D0-9DF1-444553540000}']
		function i_IsSelectedObject(const AnObjectID: TM2ID; out AnIs: Bool): HResult; stdcall;
		function i_SelectAloneObject(const AnObjectID: TM2ID): HResult; stdcall;
		function i_SelectObject(const AnObjectID: TM2ID): HResult; stdcall;
		function i_ToggleObjectSelection(const AnObjectID: TM2ID): HResult; stdcall;
		function i_UnselectObject(const AnObjectID: TM2ID): HResult; stdcall;
		function i_UnselectAllObjects: HResult; stdcall;
		function i_FitObjects: HResult; stdcall;
		function i_GetSelectedObjectList(out AList: IM2IDsList): HResult; stdcall;

		function i_SetScale(AScale: Double): HResult; stdcall;
		function i_GetScale(out AScale: Double): HResult; stdcall;

		function i_RegisterCursor(ACursor: HCursor; out ARegCursor: Longint): HResult; stdcall;
		function i_SetCursor(ARegCursor: Longint): HResult; stdcall;
		function i_GetCursor(out ARegCursor: Longint): HResult; stdcall;

		function i_SetCaptureEditor(const AnEditor: IM2Editor): HResult; stdcall;
		function i_SetTimer(const AnEditor: IM2Editor; AnInterval: Longint): HResult; stdcall;
		function i_GetPhase(out APhase: TM2ProcessPhase): HResult; stdcall;

		function i_AddEditor(const AnEditor: IM2Editor): HResult; stdcall;
		function i_RemoveEditor(const AnEditor: IM2Editor): HResult; stdcall;
		function i_Notify(AWhat: TM2EditorNotification): HResult; stdcall;

		function i_Invalidate: HResult; stdcall;
		function i_InvalidateArea(const ARect: TM2Rect): HResult; stdcall;
		function i_ScrollBy(dx, dy: Longint): HResult; stdcall;
		function i_GetZoomRect(out aRect: TM2Rect): HResult; stdcall;
		function i_SetZoomRect(const ARect: TM2Rect): HResult; stdcall;
		function i_ZoomIn: HResult; stdcall;
		function i_ZoomOut: HResult; stdcall;
		function i_ZoomToExtent: HResult; stdcall;

		function i_StopHandler: HResult; stdcall;
		function i_SetStatusText(ASection: Longint; const AText: TM2String): HResult; stdcall;

		function i_PointToDevice(const APoint: TM2Point; out AnOutPoint: TPoint): HResult; stdcall;
		function i_PointFromDevice(APoint: TPoint; out AnOutPoint: TM2Point): HResult; stdcall;
		function i_SizeToDevice(ASize: Double; out AnOutSize: Longint): HResult; stdcall;
		function i_SizeFromDevice(ASize: Longint; out AnOutSize: Double): HResult; stdcall;
		function i_RectToDevice(const aRect: TM2Rect; out anOutRect: TRect): HResult; stdcall;
		function i_RectFromDevice(const aRect: TRect; out anOutRect: TM2Rect): HResult; stdcall;

		function i_DrawPolyline(ADrawMode: Longint; const APen: TM2Pen;
				APoints: PM2Point; ACount: Longint): HResult; stdcall;
		function i_DrawPolygon(ADrawMode: Longint; APolyFillMode: Longint;
				const APen: TM2Pen; const ABrush: TM2Brush; APoints: PM2Point; ACount: Longint): HResult; stdcall;
		function i_DrawArc(ADrawMode: Longint; const APen: TM2Pen;
				const APoint1: TM2Point; const APoint2: TM2Point; AConvexity: Double): HResult; stdcall;
		function i_DrawContour(ADrawMode: Longint; APolyFillMode: Longint;
				const APen: TM2Pen; const ABrush: TM2Brush; const AContour: IM2Contour): HResult; stdcall;
		function i_DrawHandler(const APoint: TM2Point; AState: TM2HandlerState): HResult; stdcall;
		function i_DrawText(ADrawMode: Longint; const AFont: TM2Font;
				const APoint1: TM2Point; const APoint2: TM2Point; AText: PChar): HResult; stdcall;
		function i_GetTextSize(const AFont: TM2Font; AText: PChar;
				out ASize: TM2Point): HResult; stdcall;

		function i_GetDirections(out xAngle, yAngle: double): HResult; stdcall;
		function i_GetMapImage(const aCenter: TM2Point; aScale: double; xAngle: double; yAngle: double;
				aDeviceSize: TPoint; aBkColor: TM2Color; aResolution: TPoint; out aDataObject: IDataObject): HResult; stdcall;
	end;

	TM2MapView = object
		OleObject: IM2MapView;
		Dummy: Longint;
		
		function IsSelectedObject(const AnObjectID: TM2ID): Boolean;
		procedure SelectAloneObject(const AnObjectID: TM2ID);
		procedure SelectObject(const AnObjectID: TM2ID);
		procedure ToggleObjectSelection(const AnObjectID: TM2ID);
		procedure UnselectObject(const AnObjectID: TM2ID);
		procedure UnselectAllObjects;
		procedure FitObjects;
		function GetSelectedObjectList: IM2IDsList;

		procedure SetScale(AScale: Double);
		function Scale: Double;

		function RegisterCursor(ACursor: HCursor): Longint;
		procedure SetCursor(ARegCursor: Longint);
		function GetCursor: Longint;

		procedure SetCaptureEditor(const AnEditor: IM2Editor);
		procedure SetTimer(const AnEditor: IM2Editor; AnInterval: Longint);
		function GetPhase: TM2ProcessPhase;

		procedure AddEditor(const AnEditor: IM2Editor);
		procedure RemoveEditor(const AnEditor: IM2Editor);
		procedure Notify(AWhat: TM2EditorNotification);

		procedure Invalidate;
		procedure InvalidateArea(const ARect: TM2Rect);
		procedure ScrollBy(dx, dy: Longint);
		function ZoomRect: TM2Rect;
		procedure SetZoomRect(const ARect: TM2Rect);
		procedure ZoomIn;
		procedure ZoomOut;
		procedure ZoomToExtent;

		procedure StopHandler;
		procedure SetStatusText(ASection: Longint; const AText: TM2String);

		function PointToDevice(const APoint: TM2Point): TPoint;
		function PointFromDevice(APoint: TPoint): TM2Point;
		function SizeToDevice(ASize: Double): Longint;
		function SizeFromDevice(ASize: Longint): Double;
		function RectToDevice(const aRect: TM2Rect): TRect;
		function RectFromDevice(const aRect: TRect): TM2Rect;

		procedure DrawPolyline(ADrawMode: Longint; const APen: TM2Pen;
				APoints: PM2Point; ACount: Longint);
		procedure DrawPolygon(ADrawMode: Longint; APolyFillMode: Longint;
				const APen: TM2Pen; const ABrush: TM2Brush; APoints: PM2Point; ACount: Longint);
		procedure DrawArc(ADrawMode: Longint; const APen: TM2Pen;
				const APoint1: TM2Point; const APoint2: TM2Point; AConvexity: Double);
		procedure DrawContour(ADrawMode: Longint; APolyFillMode: Longint;
				const APen: TM2Pen; const ABrush: TM2Brush; const AContour: IM2Contour);
		procedure DrawHandler(const APoint: TM2Point; AState: TM2HandlerState);
		procedure DrawText(ADrawMode: Longint; const AFont: TM2Font;
				const APoint1: TM2Point; const APoint2: TM2Point; AText: PChar);
		function GetTextSize(const AFont: TM2Font; AText: PChar): TM2Point;

		procedure GetDirections(out xAngle, yAngle: double);
		function GetMapImage(const aCenter: TM2Point; aScale: double; xAngle: double; yAngle: double;
				aDeviceSize: TPoint; aBkColor: TM2Color; aResolution: TPoint): IDataObject;

//		property Scale: Double read GetScale write SetScale;
//		property ZoomRect: TM2Rect read GetZoomRect write SetZoomRect;
	end;

	IM2ErrorInfo = interface(IUnknown)
		['{C8F84416-1878-11D0-9DF1-444553540000}']
		function i_SetInfo(const ASource, AMessage: TM2String): HResult; stdcall;
		function i_GetInfo(out ASource, AMessage: TM2String): HResult; stdcall;
	end;

	TM2ContourOperation = Longint;
	TM2ContourRelation = Longint;

	IM2GeometryLib = interface(IUnknown)
		['{C8F84417-1878-11D0-9DF1-444553540000}']
		function i_CalcContourSquare(const aSrc: IM2Contour; out aSquare: double): HResult; stdcall;
		function i_CalcContourPerimeter(const aSrc: IM2Contour; out aPerimeter: double): HResult; stdcall;
		function i_CalcContoursRelation(const aSrc, aTest: IM2Contour; out aRelation: TM2ContourRelation): HResult; stdcall;

		function i_ContourOperation(const aDst, aSrc: IM2Contour; anOp: TM2ContourOperation): HResult; stdcall;
		function i_ContourOperationList(const aDst: IM2Contour; aSrcList: PIM2Contour;
				aCount: Longint; anOp: TM2ContourOperation; const aCallback: IM2Callback): HResult; stdcall;
		function i_BuildBufferZone(const aDst: IM2Contour; aDistance: double): HResult; stdcall;
	end;

	TM2GeometryLib = object
		OleObject: IM2GeometryLib;
		Dummy: Longint;
		
		function CalcContourSquare(const aSrc: IM2Contour): double;
		function CalcContourPerimeter(const aSrc: IM2Contour): double;
		function CalcContoursRelation(const aSrc, aTest: IM2Contour): TM2ContourRelation;

		procedure ContourOperation(const aDst, aSrc: IM2Contour; anOp: TM2ContourOperation);
		procedure ContourOperationList(const aDst: IM2Contour; aSrcList: PIM2Contour;
				aCount: Longint; anOp: TM2ContourOperation; const aCallback: IM2Callback);
		procedure BuildBufferZone(const aDst: IM2Contour; aDistance: double);
	end;

	TM2PrefRoot = Longint;
	TM2PrefKeyName = string[63];
	TM2PrefKeyValue = string[63];

	IM2Preferences = interface(IUnknown)
		['{C8F84418-1878-11D0-9DF1-444553540000}']
		function i_SetString(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
				const aKey: TM2PrefKeyName; const aValue: TM2PrefKeyValue): HResult; stdcall;
		function i_GetString(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
				const aKey: TM2PrefKeyName; var aValue: TM2PrefKeyValue): HResult; stdcall;
		function i_DeleteKey(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
				const aKey: TM2PrefKeyName): HResult; stdcall;
	end;

	TM2Preferences = object
		OleObject: IM2Preferences;
		Dummy: Longint;
		
		procedure SetString(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
				const aKey: TM2PrefKeyName; const aValue: TM2PrefKeyValue);
		function GetString(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
				const aKey: TM2PrefKeyName; const aDefValue: TM2PrefKeyValue): TM2PrefKeyValue;
		function DeleteKey(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
				const aKey: TM2PrefKeyName): Boolean;
	end;

	IM2AddOn = interface(IUnknown)
		['{C8F844A1-1878-11D0-9DF1-444553540000}']
		function i_GetAttrs(out AnAttrs: TM2AddOnAttrs): HResult; stdcall;
		function i_Initialize(const AManager: IM2AddOnManager): HResult; stdcall;
		function i_Uninitialize: HResult; stdcall;
		function i_GetMacroList(out AList: IM2MacroAttrsList): HResult; stdcall;
		function i_ExecuteMacro(ACommand: Longint; const AParams: TM2String): HResult; stdcall;
		function i_Notify(AnAdvise: TM2Notify; const AParams: IM2ParamsList): HResult; stdcall;
		function i_GetBitmap(const aStm: IStream; aBitmap: Longint): HResult; stdcall;
	end;

	TM2AddOn = object
		OleObject: IM2AddOn;
		Dummy: Longint;
		
		procedure GetAttrs(out AnAttrs: TM2AddOnAttrs);
		procedure Initialize(const AManager: IM2AddOnManager);
		procedure Uninitialize;
		function GetMacroList: IM2MacroAttrsList;
		procedure ExecuteMacro(ACommand: Longint; const AParams: TM2String);
		procedure Notify(AnAdvise: TM2Notify; const AParams: IM2ParamsList);
		function GetBitmap(const aStm: IStream; aBitmap: Longint): Boolean;
	end;

	TM2CallbackPurpose = Longint;

	IM2Callback = interface(IUnknown)
		['{C8F844A2-1878-11D0-9DF1-444553540000}']
		function i_Callback(aPurpose: TM2CallbackPurpose; aValue: Longint): HResult; stdcall;
	end;

	TM2Callback = object
		OleObject: IM2Callback;
		Dummy: Longint;

		function Callback(aPurpose: TM2CallbackPurpose; aValue: Longint): Boolean;
	end;

const
	{Пути в Registry}
	kregAddOns = '\Software\Albea\GIS\AddOns';
	kregPlugIns = '\Software\Albea\GIS\PlugIns';
	kregAppliedAddOns = '\Software\Albea\GIS\AppliedAddOns';
	kregAppliedPlugIns = '\Software\Albea\GIS\AppliedPlugIns';

	{Automation-объект ГИС}
	kdispGisApplication = 'Ingeo.Application';

	{M2 Type Library Version is 2.0}
	kverTypeLibMaj = 2;
	kverTypeLibMin = 0;

	LCID_M2: TLCID = 0; {Neutral}

	{C8F84400-1878-11D0-9DF1-444553540000}
	LIBID_M2: TGUID = (
		D1: $C8F84400;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84401-1878-11D0-9DF1-444553540000}
	CLSID_M2Application: TCLSID = (
		D1: $C8F84401;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{Интерфейсы}
	{C8F84451-1878-11D0-9DF1-444553540000}
	IID_IM2Contour: TIID = (
		D1: $C8F84451;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84452-1878-11D0-9DF1-444553540000}
	IID_IM2ShapeList: TIID = (
		D1: $C8F84452;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84552-1878-11D0-9DF1-444553540000}
	IID_IM2ShapeListPrivate: TIID = (
		D1: $C8F84552;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84458-1878-11D0-9DF1-444553540000}
	IID_IM2Style: TIID = (
		D1: $C8F84458;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84440-1878-11D0-9DF1-444553540000}
	IID_IM2IDsEnum: TIID = (
		D1: $C8F84440;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84441-1878-11D0-9DF1-444553540000}
	IID_IM2IDsList: TIID = (
		D1: $C8F84441;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84442-1878-11D0-9DF1-444553540000}
	IID_IM2MacroAttrsList: TIID = (
		D1: $C8F84442;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84443-1878-11D0-9DF1-444553540000}
	IID_IM2ParamsList: TIID = (
		D1: $C8F84443;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84444-1878-11D0-9DF1-444553540000}
	IID_IM2ContextMacroAttrsList: TIID = (
		D1: $C8F84444;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84445-1878-11D0-9DF1-444553540000}
	IID_IM2TopoLinkList: TIID = (
		D1: $C8F84445;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84453-1878-11D0-9DF1-444553540000}
	IID_IM2Editor: TIID = (
		D1: $C8F84453;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84410-1878-11D0-9DF1-444553540000}
	IID_IM2Application: TIID = (
		D1: $C8F84410;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84411-1878-11D0-9DF1-444553540000}
	IID_IM2AddOnManager: TIID = (
		D1: $C8F84411;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84412-1878-11D0-9DF1-444553540000}
	IID_IM2GISDatabase: TIID = (
		D1: $C8F84412;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84413-1878-11D0-9DF1-444553540000}
	IID_IM2MapProject: TIID = (
		D1: $C8F84413;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84414-1878-11D0-9DF1-444553540000}
	IID_IM2MapObjects: TIID = (
		D1: $C8F84414;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84415-1878-11D0-9DF1-444553540000}
	IID_IM2MapView: TIID = (
		D1: $C8F84415;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84416-1878-11D0-9DF1-444553540000}
	IID_IM2ErrorInfo: TIID = (
		D1: $C8F84416;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84417-1878-11D0-9DF1-444553540000}
	IID_IM2GeometryLib: TIID = (
		D1: $C8F84417;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F84418-1878-11D0-9DF1-444553540000}
	IID_IM2Preferences: TIID = (
		D1: $C8F84418;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F844A1-1878-11D0-9DF1-444553540000}
	IID_IM2AddOn: TIID = (
		D1: $C8F844A1;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	{C8F844A2-1878-11D0-9DF1-444553540000}
	IID_IM2Callback: TIID = (
		D1: $C8F844A2;
		D2: $1878;
		D3: $11D0;
		D4: ($9D, $F1, $44, $45, $53, $54, $00, $00)
	);

	function RaiseM2Exception(const AMsg, ASrc: string): HResult;
	function GetEResultText: string;
	function CheckEResult(AResult: HResult): HResult;
	function ShowEResult(AResult: HResult): HResult;

var
	gErrorInfo: IM2ErrorInfo = nil;

implementation

uses
	Dialogs, InControlUtils, AClasses;

function RaiseM2Exception(const AMsg, ASrc: string): HResult;
begin
	if Assigned(gErrorInfo) then
		gErrorInfo.i_SetInfo(ASrc, AMsg);
	Result := E_FAIL;
end;

function GetEResultText: string;
var
	aSrc, aMsg: TM2String;
begin
	Result := '';
	if Assigned(gErrorInfo) and Succeeded(gErrorInfo.i_GetInfo(aSrc, aMsg)) then
		Result := aMsg+'. ['+aSrc+']';
end;

function CheckEResult(AResult: HResult): HResult;
begin
	Result := AResult;
	if FAILED(AResult) then
		raise EHResultError.Create(GetEResultText);
end;

function ShowEResult(AResult: HResult): HResult;
begin
	Result := AResult;
	if FAILED(AResult) then
		ShowMessageBox(GetEResultText, MB_OK or MB_ICONERROR);
end;

{ TM2IDsList }

function TM2IDsList.Items(i: Longint): TM2ID;
begin
	CheckEResult(OleObject.i_GetItem(i, Result));
end;

function TM2IDsList.Count: Longint;
begin
	CheckEResult(OleObject.i_GetCount(Result));
end;

procedure TM2IDsList.Add(const anItem: TM2ID);
begin
	CheckEResult(OleObject.i_Add(-1, anItem));
end;

procedure TM2IDsList.Insert(i: Longint; const anItem: TM2ID);
begin
	CheckEResult(OleObject.i_Add(i, anItem));
end;

procedure TM2IDsList.Change(i: Longint; const anItem: TM2ID);
begin
	CheckEResult(OleObject.i_Change(i, anItem));
end;

procedure TM2IDsList.Delete(i: Longint);
begin
	CheckEResult(OleObject.i_Delete(i));
end;

procedure TM2IDsList.Clear;
begin
	CheckEResult(OleObject.i_Clear);
end;

{ TM2Contour }

procedure TM2Contour.Clear;
begin
	CheckEResult(OleObject.i_Clear);
end;

function TM2Contour.GetFirstCommand(out aCommand: TM2ContourCommand): Boolean;
begin
	Result := CheckEResult(OleObject.i_GetFirstCommand(aCommand)) = S_OK;
end;

function TM2Contour.GetNextCommand(out aCommand: TM2ContourCommand): Boolean;
begin
	Result := CheckEResult(OleObject.i_GetNextCommand(aCommand)) = S_OK;
end;

procedure TM2Contour.AddCommand(const aCommand: TM2ContourCommand);
begin
	CheckEResult(OleObject.i_AddCommand(aCommand));
end;

procedure TM2Contour.InsertCommand(aBefore: Longint; const aCommand: TM2ContourCommand);
begin
	CheckEResult(OleObject.i_InsertCommand(aBefore, aCommand));
end;

procedure TM2Contour.SetCommand(anIndex: Longint; const aCommand: TM2ContourCommand);
begin
	CheckEResult(OleObject.i_SetCommand(anIndex, aCommand));
end;

procedure TM2Contour.DeleteCommand(anIndex: Longint);
begin
	CheckEResult(OleObject.i_DeleteCommand(anIndex));
end;

procedure TM2Contour.GetCommand(AnIndex: Longint; out ACommand: TM2ContourCommand);
begin
	CheckEResult(OleObject.i_GetCommand(AnIndex, ACommand));
end;

function TM2Contour.Count: Longint;
begin
	CheckEResult(OleObject.i_GetCount(Result));
end;

function TM2Contour.Clone: IM2Contour;
begin
	CheckEResult(OleObject.i_Clone(Result));
end;

{ TM2ShapeList }

procedure TM2ShapeList.Clear;
begin
	CheckEResult(OleObject.i_Clear);
end;

procedure TM2ShapeList.Add(const aContour: IM2Contour; const aStyleID: TM2ID);
begin
	CheckEResult(OleObject.i_Add(aContour, aStyleID));
end;

procedure TM2ShapeList.Insert(aBefore: Longint; const aContour: IM2Contour; const aStyleID: TM2ID);
begin
	CheckEResult(OleObject.i_Insert(aBefore, aContour, aStyleID));
end;

procedure TM2ShapeList.Delete(anIndex: Longint);
begin
	CheckEResult(OleObject.i_Delete(anIndex));
end;

function TM2ShapeList.Count: Longint;
begin
	CheckEResult(OleObject.i_GetCount(Result));
end;

function TM2ShapeList.Contours(anIndex: Longint): IM2Contour;
begin
	CheckEResult(OleObject.i_GetContour(anIndex, Result));
end;

function TM2ShapeList.StyleIDs(anIndex: Longint): TM2ID;
begin
	CheckEResult(OleObject.i_GetStyleID(anIndex, Result));
end;

procedure TM2ShapeList.SetStyleID(anIndex: Longint; const aStyleID: TM2ID);
begin
	CheckEResult(OleObject.i_SetStyleID(anIndex, aStyleID));
end;

{ TM2ShapeListPrivate }

function TM2ShapeListPrivate.ModifyOwnObject(const anObjectID: TM2ID): Boolean;
begin
	Result := CheckEResult(OleObject.i_ModifyOwnObject(anObjectID)) = S_OK;
end;

{ TM2Style }

function TM2Style.ID: TM2ID;
begin
	CheckEResult(OleObject.i_GetID(Result));
end;

function TM2Style.GetLayerList: IM2IDsList;
begin
	CheckEResult(OleObject.i_GetLayerList(Result));
end;

procedure TM2Style.GetAttrs(out anAttrs: TM2StyleAttrs);
begin
	CheckEResult(OleObject.i_GetAttrs(anAttrs));
end;

function TM2Style.PainterCount: Longint;
begin
	CheckEResult(OleObject.i_GetPainterCount(Result));
end;

procedure TM2Style.GetPainterAttrs(anIndex: Longint; out anAttrs: TM2PainterAttrs);
begin
	CheckEResult(OleObject.i_GetPainterAttrs(anIndex, anAttrs));
end;

procedure TM2Style.AddPainter(const anAttrs: TM2PainterAttrs);
begin
	CheckEResult(OleObject.i_AddPainter(-1, anAttrs));
end;

procedure TM2Style.InsertPainter(anIndex: Longint; const anAttrs: TM2PainterAttrs);
begin
	CheckEResult(OleObject.i_AddPainter(anIndex, anAttrs));
end;

procedure TM2Style.SetPainter(anIndex: Longint; const anAttrs: TM2PainterAttrs);
begin
	CheckEResult(OleObject.i_SetPainter(anIndex, anAttrs));
end;

procedure TM2Style.DeletePainter(anIndex: Longint);
begin
	CheckEResult(OleObject.i_DeletePainter(anIndex));
end;

{ TM2IDsEnum }

function TM2IDsEnum.Next(out anID: TM2ID): Boolean;
begin
	Result := CheckEResult(OleObject.i_Next(anID)) = S_OK;
end;

function TM2IDsEnum.Skip(aCount: Longint): Boolean;
begin
	Result := CheckEResult(OleObject.i_Skip(aCount)) = S_OK;
end;

procedure TM2IDsEnum.Reset;
begin
	CheckEResult(OleObject.i_Reset);
end;

{ TM2MacroAttrsList }

procedure TM2MacroAttrsList.GetItem(i: Longint; out AnItem: TM2MacroAttrs);
begin
	CheckEResult(OleObject.i_GetItem(i, AnItem));
end;

function TM2MacroAttrsList.Count: Longint;
begin
	CheckEResult(OleObject.i_GetCount(Result));
end;

procedure TM2MacroAttrsList.Clear;
begin
	CheckEResult(OleObject.i_Clear);
end;

procedure TM2MacroAttrsList.Add(const anItem: TM2MacroAttrs);
begin
	CheckEResult(OleObject.i_Add(-1, anItem));
end;

procedure TM2MacroAttrsList.Insert(i: Longint; const anItem: TM2MacroAttrs);
begin
	CheckEResult(OleObject.i_Add(i, anItem));
end;

{ TM2ParamsList }

function TM2ParamsList.Items(AKey: Longint): TM2String;
begin
	CheckEResult(OleObject.i_GetItem(AKey, Result));
end;

function TM2ParamsList.Contains(aKey: Longint): Boolean;
begin
	Result := CheckEResult(OleObject.i_Contains(aKey)) = S_OK;
end;

procedure TM2ParamsList.Clear;
begin
	CheckEResult(OleObject.i_Clear);
end;

procedure TM2ParamsList.Add(aKey: Longint; const anItem: TM2String);
begin
	CheckEResult(OleObject.i_Add(aKey, anItem));
end;

{ TM2ContextMacroAttrsList }

procedure TM2ContextMacroAttrsList.GetItem(i: Longint; out AnItem: TM2ContextMacroAttrs);
begin
	CheckEResult(OleObject.i_GetItem(i, AnItem));
end;

function TM2ContextMacroAttrsList.Count: Longint;
begin
	CheckEResult(OleObject.i_GetCount(Result));
end;

procedure TM2ContextMacroAttrsList.Clear;
begin
	CheckEResult(OleObject.i_Clear);
end;

procedure TM2ContextMacroAttrsList.Add(const anItem: TM2ContextMacroAttrs);
begin
	CheckEResult(OleObject.i_Add(-1, anItem));
end;

procedure TM2ContextMacroAttrsList.Insert(i: Longint; const anItem: TM2ContextMacroAttrs);
begin
	CheckEResult(OleObject.i_Add(i, anItem));
end;

{ TM2TopoLinkList }

procedure TM2TopoLinkList.GetItem(i: Longint; out anItem: TM2TopoLink);
begin
	CheckEResult(OleObject.i_GetItem(i, anItem));
end;

function TM2TopoLinkList.Count: Longint;
begin
	CheckEResult(OleObject.i_GetCount(Result));
end;

{ TM2Editor }

function TM2Editor.GetEditorOptions: TM2EditorOptions;
begin
	CheckEResult(OleObject.i_GetEditorOptions(Result));
end;

procedure TM2Editor.HideDragging;
begin
	CheckEResult(OleObject.i_HideDragging);
end;

procedure TM2Editor.ShowDragging(AMouse: TPoint);
begin
	CheckEResult(OleObject.i_ShowDragging(AMouse));
end;

procedure TM2Editor.MouseDown(AButton: TM2MouseButton; AShift: TM2ShiftState; AMouse: TPoint);
begin
	CheckEResult(OleObject.i_MouseDown(AButton, AShift, AMouse));
end;

procedure TM2Editor.MouseMove(AShift: TM2ShiftState; AMouse: TPoint);
begin
	CheckEResult(OleObject.i_MouseMove(AShift, AMouse));
end;

procedure TM2Editor.MouseUp(AButton: TM2MouseButton; AShift: TM2ShiftState; AMouse: TPoint);
begin
	CheckEResult(OleObject.i_MouseUp(AButton, AShift, AMouse));
end;

procedure TM2Editor.KeyDown(Key: Word; AShift: TM2ShiftState);
begin
	CheckEResult(OleObject.i_KeyDown(Key, AShift));
end;

procedure TM2Editor.KeyUp(Key: Word; AShift: TM2ShiftState);
begin
	CheckEResult(OleObject.i_KeyUp(Key, AShift));
end;

procedure TM2Editor.Timer;
begin
	CheckEResult(OleObject.i_Timer);
end;

procedure TM2Editor.Notification(AWhat: TM2EditorNotification);
begin
	CheckEResult(OleObject.i_Notification(AWhat));
end;

function TM2Editor.GetContextMacroList(AMouse: TPoint): IM2ContextMacroAttrsList;
begin
	CheckEResult(OleObject.i_GetContextMacroList(Result, AMouse));
end;

procedure TM2Editor.ExecuteMacro(ACommand: Longint; const AParams: TM2String);
begin
	CheckEResult(OleObject.i_ExecuteMacro(ACommand, AParams));
end;

procedure TM2Editor.Cancel;
begin
	CheckEResult(OleObject.i_Cancel);
end;

procedure TM2Editor.Paint;
begin
	CheckEResult(OleObject.i_Paint);
end;

{ TM2Application }

function TM2Application.Application: IM2Application;
begin
	CheckDispResult(OleObject.i_GetApplication(Result));
end;

function TM2Application.Caption: string;
var
	retval: WideString;
begin
	CheckDispResult(OleObject.i_GetCaption(retval));
	Result := retval;
end;

function TM2Application.FullName: string;
var
	retval: WideString;
begin
	CheckDispResult(OleObject.i_GetFullName(retval));
	Result := retval;
end;

function TM2Application.Path: string;
var
	retval: WideString;
begin
	CheckDispResult(OleObject.i_GetPath(retval));
	Result := retval;
end;

function TM2Application.Name: string;
var
	retval: WideString;
begin
	CheckDispResult(OleObject.i_GetName(retval));
	Result := retval;
end;

function TM2Application.Parent: IM2Application;
begin
	CheckDispResult(OleObject.i_GetParent(Result));
end;

procedure TM2Application.Quit;
begin
	CheckDispResult(OleObject.i_Quit);
end;

{ TM2AddOnManager }

function TM2AddOnManager.GetMainWindow: HWnd;
begin
	CheckEResult(OleObject.i_GetMainWindow(Result));
end;

function TM2AddOnManager.GetAppDesktop: THandle;
begin
	CheckEResult(OleObject.i_GetAppDesktop(Result));
end;

{ TM2GISDatabase }

function TM2GISDatabase.DatabaseName: TM2String;
begin
	CheckEResult(OleObject.i_GetDatabaseName(Result));
end;

function TM2GISDatabase.GetUniqueID: TM2ID;
begin
	CheckEResult(OleObject.i_GetUniqueID(Result));
end;

function TM2GISDatabase.GetAreaList: IM2IDsList;
begin
	CheckEResult(OleObject.i_GetAreaList(Result));
end;

procedure TM2GISDatabase.GetAreaAttrs(const AnID: TM2ID; out AnAttrs: TM2AreaAttrs);
begin
	CheckEResult(OleObject.i_GetAreaAttrs(AnID, AnAttrs));
end;

function TM2GISDatabase.GetMapList(const AnAreaID: TM2ID): IM2IDsList;
begin
	CheckEResult(OleObject.i_GetMapList(AnAreaID, Result));
end;

procedure TM2GISDatabase.GetMapAttrs(const AnID: TM2ID; out AnAttrs: TM2MapAttrs);
begin
	CheckEResult(OleObject.i_GetMapAttrs(AnID, AnAttrs));
end;

function TM2GISDatabase.GetLayerList(const AMapID: TM2ID): IM2IDsList;
begin
	CheckEResult(OleObject.i_GetLayerList(AMapID, Result));
end;

procedure TM2GISDatabase.GetLayerAttrs(const AnID: TM2ID; out AnAttrs: TM2LayerAttrs);
begin
	CheckEResult(OleObject.i_GetLayerAttrs(AnID, AnAttrs));
end;

function TM2GISDatabase.GetStyleList(const ALayerID: TM2ID): IM2IDsList;
begin
	CheckEResult(OleObject.i_GetStyleList(ALayerID, Result));
end;

function TM2GISDatabase.GetStyle(const AnID: TM2ID): IM2Style;
begin
	CheckEResult(OleObject.i_GetStyle(AnID, Result));
end;

function TM2GISDatabase.AddMap(const anAttrs: TM2MapAttrs): TM2ID;
begin
	CheckEResult(OleObject.i_AddMap(anAttrs, Result));
end;

function TM2GISDatabase.AddLayer(const anAttrs: TM2LayerAttrs): TM2ID;
begin
	CheckEResult(OleObject.i_AddLayer(anAttrs, Result));
end;

function TM2GISDatabase.AddStyle(const aLayerID: TM2ID; const anAttrs: TM2StyleAttrs): TM2ID;
begin
	CheckEResult(OleObject.i_AddStyle(aLayerID, anAttrs, Result));
end;

function TM2GISDatabase.AddTable(const aLayerID: TM2ID; const anAttrs: TM2CreateTableAttrs): TM2ID;
begin
	CheckEResult(OleObject.i_AddTable(aLayerID, anAttrs, Result));
end;

function TM2GISDatabase.DatabaseID: Longint;
begin
	CheckEResult(OleObject.i_GetDatabaseID(Result));
end;

function TM2GISDatabase.CurrentUser: TM2ID;
begin
	CheckEResult(OleObject.i_GetCurrentUser(Result));
end;

function TM2GISDatabase.GetUserList: IM2IDsList;
begin
	CheckEResult(OleObject.i_GetUserList(Result));
end;

procedure TM2GISDatabase.GetUserAttrs(const anUserID: TM2ID; out anAttrs: TM2UserAttrs);
begin
	CheckEResult(OleObject.i_GetUserAttrs(anUserID, anAttrs));
end;

function TM2GISDatabase.GetTableList(const aLayerID: TM2ID): IM2IDsList;
begin
	CheckEResult(OleObject.i_GetTableList(aLayerID, Result));
end;

procedure TM2GISDatabase.GetTableAttrs(const aTableID: TM2ID; out anAttrs: TM2TableAttrs);
begin
	CheckEResult(OleObject.i_GetTableAttrs(aTableID, anAttrs));
end;

function TM2GISDatabase.GetAddonData(const aKey: TM2String; const aStm: IStream): Boolean;
begin
	Result := CheckEResult(OleObject.i_GetAddonData(aKey, aStm)) = S_OK;
end;

procedure TM2GISDatabase.SetAddonData(const aKey: TM2String; const aStm: IStream);
begin
	CheckEResult(OleObject.i_SetAddonData(aKey, aStm));
end;

{ TM2MapProject }

function TM2MapProject.ID: TM2ID;
begin
	CheckEResult(OleObject.i_GetID(Result));
end;

procedure TM2MapProject.GetAttrs(out AnAttrs: TM2ProjectAttrs);
begin
	CheckEResult(OleObject.i_GetAttrs(AnAttrs));
end;

procedure TM2MapProject.SetActiveMap(const AMapID: TM2ID);
begin
	CheckEResult(OleObject.i_SetActiveMap(AMapID));
end;

procedure TM2MapProject.SetActiveLayer(const ALayerID: TM2ID);
begin
	CheckEResult(OleObject.i_SetActiveLayer(ALayerID));
end;

function TM2MapProject.ActiveMap: TM2ID;
begin
	CheckEResult(OleObject.i_GetActiveMap(Result));
end;

function TM2MapProject.ActiveLayer: TM2ID;
begin
	CheckEResult(OleObject.i_GetActiveLayer(Result));
end;

procedure TM2MapProject.AddMap(const aMapID: TM2ID);
begin
	CheckEResult(OleObject.i_AddMap(aMapID));
end;

function TM2MapProject.GetMapList: IM2IDsList;
begin
	CheckEResult(OleObject.i_GetMapList(Result));
end;

function TM2MapProject.GetLayerList(const aMapID: TM2ID): IM2IDsList;
begin
	CheckEResult(OleObject.i_GetLayerList(aMapID, Result));
end;

{ TM2MapObjects }

function TM2MapObjects.CreateContour: IM2Contour;
begin
	CheckEResult(OleObject.i_CreateContour(Result));
end;

function TM2MapObjects.CreateShapeList: IM2ShapeList;
begin
	CheckEResult(OleObject.i_CreateShapeList(Result));
end;

function TM2MapObjects.AddObject(const aLayerID: TM2ID; const aShapeList: IM2ShapeList): TM2ID;
begin
	CheckEResult(OleObject.i_AddObject(aLayerID, aShapeList, Result));
end;

function TM2MapObjects.GetObjectLayerID(const anObjectID: TM2ID): TM2ID;
begin
	CheckEResult(OleObject.i_GetObjectLayerID(anObjectID, Result));
end;

function TM2MapObjects.GetObjectShapeList(const anObjectID: TM2ID): IM2ShapeList;
begin
	CheckEResult(OleObject.i_GetObjectShapeList(anObjectID, Result));
end;

procedure TM2MapObjects.DeleteObject(const AnObjectID: TM2ID);
begin
	CheckEResult(OleObject.i_DeleteObject(AnObjectID));
end;

procedure TM2MapObjects.ModifyObject(const AnObjectID: TM2ID; const AShapeList: IM2ShapeList);
begin
	CheckEResult(OleObject.i_ModifyObject(AnObjectID, AShapeList));
end;

function TM2MapObjects.FindObjectAtPos(const ALayer: TM2ID; AnOnlyVisible: BOOL;
		const APoint: TM2Point; out AShapeIndex: Longint): TM2ID;
begin
	CheckEResult(OleObject.i_FindObjectAtPos(ALayer, AnOnlyVisible, APoint, Result, AShapeIndex));
end;

function TM2MapObjects.FindIntersectedObjects(const ALayer: TM2ID; AnOnlyVisible: BOOL; const ARect: TM2Rect;
		AnOnlyEnclosed: BOOL): IM2IDsList;
begin
	CheckEResult(OleObject.i_FindIntersectedObjects(ALayer, AnOnlyVisible, ARect, AnOnlyEnclosed, Result));
end;

procedure TM2MapObjects.ObjectDataChanged(const AnObjectID: TM2ID);
begin
	CheckEResult(OleObject.i_ObjectDataChanged(AnObjectID));
end;

function TM2MapObjects.GetCenter(const APt1: TM2Point; const APt2: TM2Point; const APt: TM2Point;
		out ADelta: Double): TM2Point;
begin
	CheckEResult(OleObject.i_GetCenter(APt1, APt2, APt, ADelta, Result));
end;

function TM2MapObjects.GetCenter2(const APt1: TM2Point; const APt2: TM2Point; AConvexity: Double;
		out ADelta: Double): TM2Point;
begin
	CheckEResult(OleObject.i_GetCenter2(APt1, APt2, AConvexity, ADelta, Result));
end;

function TM2MapObjects.GetConvexity(const APt1: TM2Point; const APt2: TM2Point; const APt: TM2Point): Double;
begin
	CheckEResult(OleObject.i_GetConvexity(APt1, APt2, APt, Result));
end;

procedure TM2MapObjects.BeginUpdate;
begin
	CheckEResult(OleObject.i_BeginUpdate);
end;

procedure TM2MapObjects.EndUpdate;
begin
	CheckEResult(OleObject.i_EndUpdate);
end;

function TM2MapObjects.GetObjectsEnum(const aLayerID: TM2ID): IM2IDsEnum;
begin
	CheckEResult(OleObject.i_GetObjectsEnum(aLayerID, Result));
end;

function TM2MapObjects.GetObjectBounds(const anObjectID: TM2ID): TM2Rect;
begin
	CheckEResult(OleObject.i_GetObjectBounds(anObjectID, Result));
end;

procedure TM2MapObjects.GetObjectData(const anObjectID: TM2ID; aFieldData: Boolean; out aData: TM2ObjectData);
begin
	CheckEResult(OleObject.i_GetObjectData(anObjectID, aFieldData, aData));
end;

procedure TM2MapObjects.SetObjectData(const anObjectID: TM2ID; aFieldData: Boolean; const aData: TM2ObjectData);
begin
	CheckEResult(OleObject.i_SetObjectData(anObjectID, aFieldData, aData));
end;

procedure TM2MapObjects.Undo(aCount: Longint);
begin
	CheckEResult(OleObject.i_Undo(aCount));
end;

procedure TM2MapObjects.AddTopoLinks(const anID: TM2ID; const aList: IM2IDsList);
begin
	CheckEResult(OleObject.i_AddTopoLinks(anID, aList));
end;

procedure TM2MapObjects.DeleteTopoLinks(const anID: TM2ID; const aList: IM2IDsList);
begin
	CheckEResult(OleObject.i_DeleteTopoLinks(anID, aList));
end;

function TM2MapObjects.GetTopoLinks(const anID: TM2ID): IM2IDsList;
begin
	CheckEResult(OleObject.i_GetTopoLinks(anID, Result));
end;

function TM2MapObjects.GetTopoLinksInfo(const anID: TM2ID; const aList: IM2IDsList): IM2TopoLinkList;
begin
	CheckEResult(OleObject.i_GetTopoLinksInfo(anID, aList, Result));
end;

function TM2MapObjects.FindTopoLinksInfo(const aContour: IM2Contour; aDistance: double; const aForLayer: TM2ID;
		const aRelLayers: IM2IDsList): IM2TopoLinkList;
begin
	CheckEResult(OleObject.i_FindTopoLinksInfo(aContour, aDistance, aForLayer, aRelLayers, Result));
end;

{ TM2MapView }

function TM2MapView.IsSelectedObject(const AnObjectID: TM2ID): Boolean;
var
	anIs: BOOL;
begin
	CheckEResult(OleObject.i_IsSelectedObject(AnObjectID, anIs));
	Result := anIs;
end;

procedure TM2MapView.SelectAloneObject(const AnObjectID: TM2ID);
begin
	CheckEResult(OleObject.i_SelectAloneObject(AnObjectID));
end;

procedure TM2MapView.SelectObject(const AnObjectID: TM2ID);
begin
	CheckEResult(OleObject.i_SelectObject(AnObjectID));
end;

procedure TM2MapView.ToggleObjectSelection(const AnObjectID: TM2ID);
begin
	CheckEResult(OleObject.i_ToggleObjectSelection(AnObjectID));
end;

procedure TM2MapView.UnselectObject(const AnObjectID: TM2ID);
begin
	CheckEResult(OleObject.i_UnselectObject(AnObjectID));
end;

procedure TM2MapView.UnselectAllObjects;
begin
	CheckEResult(OleObject.i_UnselectAllObjects);
end;

procedure TM2MapView.FitObjects;
begin
	CheckEResult(OleObject.i_FitObjects);
end;

function TM2MapView.GetSelectedObjectList: IM2IDsList;
begin
	CheckEResult(OleObject.i_GetSelectedObjectList(Result));
end;

procedure TM2MapView.SetScale(AScale: Double);
begin
	CheckEResult(OleObject.i_SetScale(AScale));
end;

function TM2MapView.Scale: Double;
begin
	CheckEResult(OleObject.i_GetScale(Result));
end;

function TM2MapView.RegisterCursor(ACursor: HCursor): Longint;
begin
	CheckEResult(OleObject.i_RegisterCursor(ACursor, Result));
end;

procedure TM2MapView.SetCursor(ARegCursor: Longint);
begin
	CheckEResult(OleObject.i_SetCursor(ARegCursor));
end;

function TM2MapView.GetCursor: Longint;
begin
	CheckEResult(OleObject.i_GetCursor(Result));
end;

procedure TM2MapView.SetCaptureEditor(const AnEditor: IM2Editor);
begin
	CheckEResult(OleObject.i_SetCaptureEditor(AnEditor));
end;

procedure TM2MapView.SetTimer(const AnEditor: IM2Editor; AnInterval: Longint);
begin
	CheckEResult(OleObject.i_SetTimer(AnEditor, AnInterval));
end;

function TM2MapView.GetPhase: TM2ProcessPhase;
begin
	CheckEResult(OleObject.i_GetPhase(Result));
end;

procedure TM2MapView.AddEditor(const AnEditor: IM2Editor);
begin
	CheckEResult(OleObject.i_AddEditor(AnEditor));
end;

procedure TM2MapView.RemoveEditor(const AnEditor: IM2Editor);
begin
	CheckEResult(OleObject.i_RemoveEditor(AnEditor));
end;

procedure TM2MapView.Notify(AWhat: TM2EditorNotification);
begin
	CheckEResult(OleObject.i_Notify(AWhat));
end;

procedure TM2MapView.Invalidate;
begin
	CheckEResult(OleObject.i_Invalidate);
end;

procedure TM2MapView.InvalidateArea(const ARect: TM2Rect);
begin
	CheckEResult(OleObject.i_InvalidateArea(ARect));
end;

procedure TM2MapView.ScrollBy(dx, dy: Longint);
begin
	CheckEResult(OleObject.i_ScrollBy(dx, dy));
end;

function TM2MapView.ZoomRect: TM2Rect;
begin
	CheckEResult(OleObject.i_GetZoomRect(Result));
end;

procedure TM2MapView.SetZoomRect(const ARect: TM2Rect);
begin
	CheckEResult(OleObject.i_SetZoomRect(ARect));
end;

procedure TM2MapView.ZoomIn;
begin
	CheckEResult(OleObject.i_ZoomIn);
end;

procedure TM2MapView.ZoomOut;
begin
	CheckEResult(OleObject.i_ZoomOut);
end;

procedure TM2MapView.ZoomToExtent;
begin
	CheckEResult(OleObject.i_ZoomToExtent);
end;

procedure TM2MapView.StopHandler;
begin
	CheckEResult(OleObject.i_StopHandler);
end;

procedure TM2MapView.SetStatusText(ASection: Longint; const AText: TM2String);
begin
	CheckEResult(OleObject.i_SetStatusText(ASection, AText));
end;

function TM2MapView.PointToDevice(const APoint: TM2Point): TPoint;
begin
	CheckEResult(OleObject.i_PointToDevice(APoint, Result));
end;

function TM2MapView.PointFromDevice(APoint: TPoint): TM2Point;
begin
	CheckEResult(OleObject.i_PointFromDevice(APoint, Result));
end;

function TM2MapView.SizeToDevice(ASize: Double): Longint;
begin
	CheckEResult(OleObject.i_SizeToDevice(ASize, Result));
end;

function TM2MapView.SizeFromDevice(ASize: Longint): Double;
begin
	CheckEResult(OleObject.i_SizeFromDevice(ASize, Result));
end;

function TM2MapView.RectToDevice(const aRect: TM2Rect): TRect;
begin
	CheckEResult(OleObject.i_RectToDevice(aRect, Result));
end;

function TM2MapView.RectFromDevice(const aRect: TRect): TM2Rect;
begin
	CheckEResult(OleObject.i_RectFromDevice(aRect, Result));
end;

procedure TM2MapView.DrawPolyline(ADrawMode: Longint; const APen: TM2Pen;
		APoints: PM2Point; ACount: Longint);
begin
	CheckEResult(OleObject.i_DrawPolyline(ADrawMode, APen, APoints, ACount));
end;

procedure TM2MapView.DrawPolygon(ADrawMode: Longint; APolyFillMode: Longint;
		const APen: TM2Pen; const ABrush: TM2Brush; APoints: PM2Point; ACount: Longint);
begin
	CheckEResult(OleObject.i_DrawPolygon(ADrawMode, APolyFillMode, APen, ABrush, APoints, ACount));
end;

procedure TM2MapView.DrawArc(ADrawMode: Longint; const APen: TM2Pen;
		const APoint1: TM2Point; const APoint2: TM2Point; AConvexity: Double);
begin
	CheckEResult(OleObject.i_DrawArc(ADrawMode, APen, APoint1, APoint2, AConvexity));
end;

procedure TM2MapView.DrawContour(ADrawMode: Longint; APolyFillMode: Longint;
		const APen: TM2Pen; const ABrush: TM2Brush; const AContour: IM2Contour);
begin
	CheckEResult(OleObject.i_DrawContour(ADrawMode, APolyFillMode, APen, ABrush, AContour));
end;

procedure TM2MapView.DrawHandler(const APoint: TM2Point; AState: TM2HandlerState);
begin
	CheckEResult(OleObject.i_DrawHandler(APoint, AState));
end;

procedure TM2MapView.DrawText(ADrawMode: Longint; const AFont: TM2Font;
		const APoint1: TM2Point; const APoint2: TM2Point; AText: PChar);
begin
	CheckEResult(OleObject.i_DrawText(ADrawMode, AFont, APoint1, APoint2, AText));
end;

function TM2MapView.GetTextSize(const AFont: TM2Font; AText: PChar): TM2Point;
begin
	CheckEResult(OleObject.i_GetTextSize(AFont, AText, Result));
end;

procedure TM2MapView.GetDirections(out xAngle, yAngle: double);
begin
	CheckEResult(OleObject.i_GetDirections(xAngle, yAngle));
end;

function TM2MapView.GetMapImage(const aCenter: TM2Point; aScale: double; xAngle: double; yAngle: double;
		aDeviceSize: TPoint; aBkColor: TM2Color; aResolution: TPoint): IDataObject;
begin
	CheckEResult(OleObject.i_GetMapImage(aCenter, aScale, xAngle, yAngle, aDeviceSize, aBkColor, aResolution, Result));
end;

{ TM2GeometryLib }

function TM2GeometryLib.CalcContourSquare(const aSrc: IM2Contour): double;
begin
	CheckEResult(OleObject.i_CalcContourSquare(aSrc, Result));
end;

function TM2GeometryLib.CalcContourPerimeter(const aSrc: IM2Contour): double;
begin
	CheckEResult(OleObject.i_CalcContourPerimeter(aSrc, Result));
end;

function TM2GeometryLib.CalcContoursRelation(const aSrc, aTest: IM2Contour): TM2ContourRelation;
begin
	CheckEResult(OleObject.i_CalcContoursRelation(aSrc, aTest, Result));
end;

procedure TM2GeometryLib.ContourOperation(const aDst, aSrc: IM2Contour; anOp: TM2ContourOperation);
begin
	CheckEResult(OleObject.i_ContourOperation(aDst, aSrc, anOp));
end;

procedure TM2GeometryLib.ContourOperationList(const aDst: IM2Contour; aSrcList: PIM2Contour;
		aCount: Longint; anOp: TM2ContourOperation; const aCallback: IM2Callback);
begin
	CheckEResult(OleObject.i_ContourOperationList(aDst, aSrcList, aCount, anOp, aCallback));
end;

procedure TM2GeometryLib.BuildBufferZone(const aDst: IM2Contour; aDistance: double);
begin
	CheckEResult(OleObject.i_BuildBufferZone(aDst, aDistance));
end;

{ TM2Preferences }

procedure TM2Preferences.SetString(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
		const aKey: TM2PrefKeyName; const aValue: TM2PrefKeyValue);
begin
	CheckEResult(OleObject.i_SetString(aRoot, anObjectID, aKey, aValue));
end;

function TM2Preferences.GetString(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
		const aKey: TM2PrefKeyName; const aDefValue: TM2PrefKeyValue): TM2PrefKeyValue;
begin
	Result := aDefValue;
	CheckEResult(OleObject.i_GetString(aRoot, anObjectID, aKey, Result));
end;

function TM2Preferences.DeleteKey(aRoot: TM2PrefRoot; const anObjectID: TM2ID;
		const aKey: TM2PrefKeyName): Boolean;
begin
	Result := CheckEResult(OleObject.i_DeleteKey(aRoot, anObjectID, aKey)) = S_OK;
end;

{ TM2AddOn }

procedure TM2AddOn.GetAttrs(out AnAttrs: TM2AddOnAttrs);
begin
	CheckEResult(OleObject.i_GetAttrs(AnAttrs));
end;

procedure TM2AddOn.Initialize(const AManager: IM2AddOnManager);
begin
	CheckEResult(OleObject.i_Initialize(AManager));
end;

procedure TM2AddOn.Uninitialize;
begin
	CheckEResult(OleObject.i_Uninitialize);
end;

function TM2AddOn.GetMacroList: IM2MacroAttrsList;
begin
	CheckEResult(OleObject.i_GetMacroList(Result));
end;

procedure TM2AddOn.ExecuteMacro(ACommand: Longint; const AParams: TM2String);
begin
	CheckEResult(OleObject.i_ExecuteMacro(ACommand, AParams));
end;

procedure TM2AddOn.Notify(AnAdvise: TM2Notify; const AParams: IM2ParamsList);
begin
	CheckEResult(OleObject.i_Notify(AnAdvise, AParams));
end;

function TM2AddOn.GetBitmap(const aStm: IStream; aBitmap: Longint): Boolean;
begin
	Result := CheckEResult(OleObject.i_GetBitmap(aStm, aBitmap)) = S_OK;
end;

{ TM2Callback }

function TM2Callback.Callback(aPurpose: TM2CallbackPurpose; aValue: Longint): Boolean;
begin
	Result := CheckEResult(OleObject.i_Callback(aPurpose, aValue)) = S_OK;
end;

end.

