method Links.Add (From as Element, To as Element, [ID as Variant])
Adds a Link object to the collection and returns a reference to the newly created object.

TypeDescription
From as Element An Element object where the link starts. The ElementFrom property of the Link indicates the element where the link starts.
To as Element An Element object where the link ends. The ElementTo property of the Link indicates the element where the link ends.
ID as Variant A Long, String or Numeric expression that indicates the unique identifier of the link. If missing, the control will automatically generate an unique identifier. The ID property specifies the link's identifier.
ReturnDescription
LinkA Link object being created.

.Use the Add method to programmatically add new link to the surface. The AddLink event notifies your application once a new link is added to the Links collection. Calling programmatically the Add method does NOT fire the CreateLink or AllowLink events. The Remove method removes a link from the surface. The Clear method clears all the links on the surface. The StartPos/EndPos properties indicates where on the starting element links starts and where on the ending elements the link ends. The ShowLinks property specifies whether the surface shows or hides the links. The OutgoingLinks property returns a safe array of outgoing links ( links that starts from the element ). The IncomingLinks property returns a safe array of incoming links ( links that ends on the element ). The AllowLinkObjects property specifies the combination of keys that allows the user to link the objects.

The following screen shot shows the surface with different type of links:

The order of the events when the user links two elements at runtime is:

The following samples show how you can add programmatically a link:

VBA (MS Access, Excell...)

With Surface1
	With .Elements
		.Add "Element <sha ;;0>A"
		.Add "Element <sha ;;0>B",96,24
	End With
	With .Links
		.Add Surface1.Elements.item(1),Surface1.Elements.item(2)
	End With
End With

VB6

With Surface1
	With .Elements
		.Add "Element <sha ;;0>A"
		.Add "Element <sha ;;0>B",96,24
	End With
	With .Links
		.Add Surface1.Elements.item(1),Surface1.Elements.item(2)
	End With
End With

VB.NET

With Exsurface1
	With .Elements
		.Add("Element <sha ;;0>A")
		.Add("Element <sha ;;0>B",96,24)
	End With
	With .Links
		.Add(Exsurface1.Elements.get_item(1),Exsurface1.Elements.get_item(2))
	End With
End With

VB.NET for /COM

With AxSurface1
	With .Elements
		.Add("Element <sha ;;0>A")
		.Add("Element <sha ;;0>B",96,24)
	End With
	With .Links
		.Add(AxSurface1.Elements.item(1),AxSurface1.Elements.item(2))
	End With
End With

C++

/*
	Copy and paste the following directives to your header file as
	it defines the namespace 'EXSURFACELib' for the library: 'ExSurface 1.0 Control Library'

	#import <ExSurface.dll>
	using namespace EXSURFACELib;
*/
EXSURFACELib::ISurfacePtr spSurface1 = GetDlgItem(IDC_SURFACE1)->GetControlUnknown();
EXSURFACELib::IElementsPtr var_Elements = spSurface1->GetElements();
	var_Elements->Add("Element <sha ;;0>A",vtMissing,vtMissing);
	var_Elements->Add("Element <sha ;;0>B",long(96),long(24));
EXSURFACELib::ILinksPtr var_Links = spSurface1->GetLinks();
	var_Links->Add(spSurface1->GetElements()->Getitem(long(1)),spSurface1->GetElements()->Getitem(long(2)),vtMissing);

C++ Builder

Exsurfacelib_tlb::IElementsPtr var_Elements = Surface1->Elements;
	var_Elements->Add(TVariant("Element <sha ;;0>A"),TNoParam(),TNoParam());
	var_Elements->Add(TVariant("Element <sha ;;0>B"),TVariant(96),TVariant(24));
Exsurfacelib_tlb::ILinksPtr var_Links = Surface1->Links;
	var_Links->Add(Surface1->Elements->get_item(TVariant(1)),Surface1->Elements->get_item(TVariant(2)),TNoParam());

C#

exontrol.EXSURFACELib.Elements var_Elements = exsurface1.Elements;
	var_Elements.Add("Element <sha ;;0>A",null,null);
	var_Elements.Add("Element <sha ;;0>B",96,24);
exontrol.EXSURFACELib.Links var_Links = exsurface1.Links;
	var_Links.Add(exsurface1.Elements[1],exsurface1.Elements[2],null);

JavaScript

<OBJECT classid="clsid:AC1DF7F4-0919-4364-8167-2F9B5155EA4B" id="Surface1"></OBJECT>

<SCRIPT LANGUAGE="JScript">
	var var_Elements = Surface1.Elements;
		var_Elements.Add("Element <sha ;;0>A",null,null);
		var_Elements.Add("Element <sha ;;0>B",96,24);
	var var_Links = Surface1.Links;
		var_Links.Add(Surface1.Elements.item(1),Surface1.Elements.item(2),null);
</SCRIPT>

C# for /COM

EXSURFACELib.Elements var_Elements = axSurface1.Elements;
	var_Elements.Add("Element <sha ;;0>A",null,null);
	var_Elements.Add("Element <sha ;;0>B",96,24);
EXSURFACELib.Links var_Links = axSurface1.Links;
	var_Links.Add(axSurface1.Elements[1],axSurface1.Elements[2],null);

X++ (Dynamics Ax 2009)

public void init()
{
	COM com_Elements,com_Links;
	anytype var_Elements,var_Links;
	;

	super();

	var_Elements = exsurface1.Elements(); com_Elements = var_Elements;
		com_Elements.Add("Element <sha ;;0>A");
		com_Elements.Add("Element <sha ;;0>B",COMVariant::createFromInt(96),COMVariant::createFromInt(24));
	var_Links = exsurface1.Links(); com_Links = var_Links;
		com_Links.Add(COM::createFromObject(exsurface1.Elements()).item(COMVariant::createFromInt(1)),COM::createFromObject(exsurface1.Elements()).item(COMVariant::createFromInt(2)));
}

Delphi 8 (.NET only)

with AxSurface1 do
begin
	with Elements do
	begin
		Add('Element <sha ;;0>A',Nil,Nil);
		Add('Element <sha ;;0>B',TObject(96),TObject(24));
	end;
	with Links do
	begin
		Add(AxSurface1.Elements.item[TObject(1)],AxSurface1.Elements.item[TObject(2)],Nil);
	end;
end

Delphi (standard)

with Surface1 do
begin
	with Elements do
	begin
		Add('Element <sha ;;0>A',Null,Null);
		Add('Element <sha ;;0>B',OleVariant(96),OleVariant(24));
	end;
	with Links do
	begin
		Add(Surface1.Elements.item[OleVariant(1)],Surface1.Elements.item[OleVariant(2)],Null);
	end;
end

VFP

with thisform.Surface1
	with .Elements
		.Add("Element <sha ;;0>A")
		.Add("Element <sha ;;0>B",96,24)
	endwith
	with .Links
		.Add(thisform.Surface1.Elements.item(1),thisform.Surface1.Elements.item(2))
	endwith
endwith

dBASE Plus

local oSurface,var_Elements,var_Links

oSurface = form.Activex1.nativeObject
var_Elements = oSurface.Elements
	var_Elements.Add("Element <sha ;;0>A")
	var_Elements.Add("Element <sha ;;0>B",96,24)
var_Links = oSurface.Links
	var_Links.Add(oSurface.Elements.item(1),oSurface.Elements.item(2))

XBasic (Alpha Five)

Dim oSurface as P
Dim var_Elements as P
Dim var_Links as P

oSurface = topparent:CONTROL_ACTIVEX1.activex
var_Elements = oSurface.Elements
	var_Elements.Add("Element <sha ;;0>A")
	var_Elements.Add("Element <sha ;;0>B",96,24)
var_Links = oSurface.Links
	var_Links.Add(oSurface.Elements.item(1),oSurface.Elements.item(2))

Visual Objects

local var_Elements as IElements
local var_Links as ILinks

var_Elements := oDCOCX_Exontrol1:Elements
	var_Elements:Add("Element <sha ;;0>A",nil,nil)
	var_Elements:Add("Element <sha ;;0>B",96,24)
var_Links := oDCOCX_Exontrol1:Links
	var_Links:Add(oDCOCX_Exontrol1:Elements:[item,1],oDCOCX_Exontrol1:Elements:[item,2],nil)

PowerBuilder

OleObject oSurface,var_Elements,var_Links

oSurface = ole_1.Object
var_Elements = oSurface.Elements
	var_Elements.Add("Element <sha ;;0>A")
	var_Elements.Add("Element <sha ;;0>B",96,24)
var_Links = oSurface.Links
	var_Links.Add(oSurface.Elements.item(1),oSurface.Elements.item(2))

Visual DataFlex

Procedure OnCreate
	Forward Send OnCreate
	Variant voElements
	Get ComElements to voElements
	Handle hoElements
	Get Create (RefClass(cComElements)) to hoElements
	Set pvComObject of hoElements to voElements
		Get ComAdd of hoElements "Element <sha ;;0>A" Nothing Nothing to Nothing
		Get ComAdd of hoElements "Element <sha ;;0>B" 96 24 to Nothing
	Send Destroy to hoElements
	Variant voLinks
	Get ComLinks to voLinks
	Handle hoLinks
	Get Create (RefClass(cComLinks)) to hoLinks
	Set pvComObject of hoLinks to voLinks
		Variant vFrom
			Variant voElements1
			Get ComElements to voElements1
			Handle hoElements1
			Get Create (RefClass(cComElements)) to hoElements1
			Set pvComObject of hoElements1 to voElements1
				Get Comitem of hoElements1 1 to vFrom
			Send Destroy to hoElements1
Variant vTo
			Variant voElements2
			Get ComElements to voElements2
			Handle hoElements2
			Get Create (RefClass(cComElements)) to hoElements2
			Set pvComObject of hoElements2 to voElements2
				Get Comitem of hoElements2 2 to vTo
			Send Destroy to hoElements2
		Get ComAdd of hoLinks vFrom vTo Nothing to Nothing
	Send Destroy to hoLinks
End_Procedure

XBase++

#include "AppEvent.ch"
#include "ActiveX.ch"

PROCEDURE Main
 	LOCAL oForm
	LOCAL nEvent := 0, mp1 := NIL, mp2 := NIL, oXbp := NIL
	LOCAL oElements
	LOCAL oLinks
	LOCAL oSurface

	oForm := XbpDialog():new( AppDesktop() )
	oForm:drawingArea:clipChildren := .T.
	oForm:create( ,,{100,100}, {640,480},, .F. )
	oForm:close  := {|| PostAppEvent( xbeP_Quit )}

	oSurface := XbpActiveXControl():new( oForm:drawingArea )
	oSurface:CLSID  := "Exontrol.Surface.1" /*{AC1DF7F4-0919-4364-8167-2F9B5155EA4B}*/
	oSurface:create(,, {10,60},{610,370} )

		oElements := oSurface:Elements()
			oElements:Add("Element <sha ;;0>A")
			oElements:Add("Element <sha ;;0>B",96,24)
		oLinks := oSurface:Links()
			oLinks:Add(oSurface:Elements:item(1),oSurface:Elements:item(2))

	oForm:Show()
	DO WHILE nEvent != xbeP_Quit
		nEvent := AppEvent( @mp1, @mp2, @oXbp )
		oXbp:handleEvent( nEvent, mp1, mp2 )
	ENDDO 
RETURN