exsurface - sample code

How can I programmatically add a child element, or create a tree/hierarchy?

VBA (MS Access, Excell...)

With Surface1
	With .Elements
		.Add("Root").ID = "rootID"
		.Insert "Child 1","rootID"
		.Insert("Child 2","rootID").ID = "childID"
		.Insert "Child 3","rootID"
		.Insert "Sub-Child 1.2","childID"
		.Insert "Sub-Child 2.2","childID"
	End With
End With

VB6

With Surface1
	With .Elements
		.Add("Root").ID = "rootID"
		.Insert "Child 1","rootID"
		.Insert("Child 2","rootID").ID = "childID"
		.Insert "Child 3","rootID"
		.Insert "Sub-Child 1.2","childID"
		.Insert "Sub-Child 2.2","childID"
	End With
End With

VB.NET

With Exsurface1
	With .Elements
		.Add("Root").ID = "rootID"
		.Insert("Child 1","rootID")
		.Insert("Child 2","rootID").ID = "childID"
		.Insert("Child 3","rootID")
		.Insert("Sub-Child 1.2","childID")
		.Insert("Sub-Child 2.2","childID")
	End With
End With

VB.NET for /COM

With AxSurface1
	With .Elements
		.Add("Root").ID = "rootID"
		.Insert("Child 1","rootID")
		.Insert("Child 2","rootID").ID = "childID"
		.Insert("Child 3","rootID")
		.Insert("Sub-Child 1.2","childID")
		.Insert("Sub-Child 2.2","childID")
	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("Root",vtMissing,vtMissing)->PutID("rootID");
	var_Elements->Insert("Child 1","rootID",vtMissing);
	var_Elements->Insert("Child 2","rootID",vtMissing)->PutID("childID");
	var_Elements->Insert("Child 3","rootID",vtMissing);
	var_Elements->Insert("Sub-Child 1.2","childID",vtMissing);
	var_Elements->Insert("Sub-Child 2.2","childID",vtMissing);

C++ Builder

Exsurfacelib_tlb::IElementsPtr var_Elements = Surface1->Elements;
	var_Elements->Add(TVariant("Root"),TNoParam(),TNoParam())->set_ID(TVariant("rootID"));
	var_Elements->Insert(TVariant("Child 1"),TVariant("rootID"),TNoParam());
	var_Elements->Insert(TVariant("Child 2"),TVariant("rootID"),TNoParam())->set_ID(TVariant("childID"));
	var_Elements->Insert(TVariant("Child 3"),TVariant("rootID"),TNoParam());
	var_Elements->Insert(TVariant("Sub-Child 1.2"),TVariant("childID"),TNoParam());
	var_Elements->Insert(TVariant("Sub-Child 2.2"),TVariant("childID"),TNoParam());

C#

exontrol.EXSURFACELib.Elements var_Elements = exsurface1.Elements;
	var_Elements.Add("Root",null,null).ID = "rootID";
	var_Elements.Insert("Child 1","rootID",null);
	var_Elements.Insert("Child 2","rootID",null).ID = "childID";
	var_Elements.Insert("Child 3","rootID",null);
	var_Elements.Insert("Sub-Child 1.2","childID",null);
	var_Elements.Insert("Sub-Child 2.2","childID",null);

JavaScript

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

<SCRIPT LANGUAGE="JScript">
	var var_Elements = Surface1.Elements;
		var_Elements.Add("Root",null,null).ID = "rootID";
		var_Elements.Insert("Child 1","rootID",null);
		var_Elements.Insert("Child 2","rootID",null).ID = "childID";
		var_Elements.Insert("Child 3","rootID",null);
		var_Elements.Insert("Sub-Child 1.2","childID",null);
		var_Elements.Insert("Sub-Child 2.2","childID",null);
</SCRIPT>

C# for /COM

EXSURFACELib.Elements var_Elements = axSurface1.Elements;
	var_Elements.Add("Root",null,null).ID = "rootID";
	var_Elements.Insert("Child 1","rootID",null);
	var_Elements.Insert("Child 2","rootID",null).ID = "childID";
	var_Elements.Insert("Child 3","rootID",null);
	var_Elements.Insert("Sub-Child 1.2","childID",null);
	var_Elements.Insert("Sub-Child 2.2","childID",null);

X++ (Dynamics Ax 2009)

public void init()
{
	COM com_Element,com_Elements;
	anytype var_Element,var_Elements;
	;

	super();

	var_Elements = exsurface1.Elements(); com_Elements = var_Elements;
		var_Element = COM::createFromObject(com_Elements.Add("Root")); com_Element = var_Element;
		com_Element.ID("rootID");
		com_Elements.Insert("Child 1","rootID");
		var_Element = COM::createFromObject(com_Elements.Insert("Child 2","rootID")); com_Element = var_Element;
		com_Element.ID("childID");
		com_Elements.Insert("Child 3","rootID");
		com_Elements.Insert("Sub-Child 1.2","childID");
		com_Elements.Insert("Sub-Child 2.2","childID");
}

Delphi 8 (.NET only)

with AxSurface1 do
begin
	with Elements do
	begin
		Add('Root',Nil,Nil).ID := 'rootID';
		Insert('Child 1','rootID',Nil);
		Insert('Child 2','rootID',Nil).ID := 'childID';
		Insert('Child 3','rootID',Nil);
		Insert('Sub-Child 1.2','childID',Nil);
		Insert('Sub-Child 2.2','childID',Nil);
	end;
end

Delphi (standard)

with Surface1 do
begin
	with Elements do
	begin
		Add('Root',Null,Null).ID := 'rootID';
		Insert('Child 1','rootID',Null);
		Insert('Child 2','rootID',Null).ID := 'childID';
		Insert('Child 3','rootID',Null);
		Insert('Sub-Child 1.2','childID',Null);
		Insert('Sub-Child 2.2','childID',Null);
	end;
end

VFP

with thisform.Surface1
	with .Elements
		.Add("Root").ID = "rootID"
		.Insert("Child 1","rootID")
		.Insert("Child 2","rootID").ID = "childID"
		.Insert("Child 3","rootID")
		.Insert("Sub-Child 1.2","childID")
		.Insert("Sub-Child 2.2","childID")
	endwith
endwith

dBASE Plus

local oSurface,var_Element,var_Element1,var_Elements

oSurface = form.Activex1.nativeObject
var_Elements = oSurface.Elements
	// var_Elements.Add("Root").ID = "rootID"
	var_Element = var_Elements.Add("Root")
	with (oSurface)
		TemplateDef = [Dim var_Element]
		TemplateDef = var_Element
		Template = [var_Element.ID = "rootID"]
	endwith
	var_Elements.Insert("Child 1","rootID")
	// var_Elements.Insert("Child 2","rootID").ID = "childID"
	var_Element1 = var_Elements.Insert("Child 2","rootID")
	with (oSurface)
		TemplateDef = [Dim var_Element1]
		TemplateDef = var_Element1
		Template = [var_Element1.ID = "childID"]
	endwith
	var_Elements.Insert("Child 3","rootID")
	var_Elements.Insert("Sub-Child 1.2","childID")
	var_Elements.Insert("Sub-Child 2.2","childID")

XBasic (Alpha Five)

Dim oSurface as P
Dim var_Element as P
Dim var_Element1 as P
Dim var_Elements as P

oSurface = topparent:CONTROL_ACTIVEX1.activex
var_Elements = oSurface.Elements
	' var_Elements.Add("Root").ID = "rootID"
	var_Element = var_Elements.Add("Root")
	oSurface.TemplateDef = "Dim var_Element"
	oSurface.TemplateDef = var_Element
	oSurface.Template = "var_Element.ID = \"rootID\""

	var_Elements.Insert("Child 1","rootID")
	' var_Elements.Insert("Child 2","rootID").ID = "childID"
	var_Element1 = var_Elements.Insert("Child 2","rootID")
	oSurface.TemplateDef = "Dim var_Element1"
	oSurface.TemplateDef = var_Element1
	oSurface.Template = "var_Element1.ID = \"childID\""

	var_Elements.Insert("Child 3","rootID")
	var_Elements.Insert("Sub-Child 1.2","childID")
	var_Elements.Insert("Sub-Child 2.2","childID")

Visual Objects

local var_Elements as IElements

var_Elements := oDCOCX_Exontrol1:Elements
	var_Elements:Add("Root",nil,nil):ID := "rootID"
	var_Elements:Insert("Child 1","rootID",nil)
	var_Elements:Insert("Child 2","rootID",nil):ID := "childID"
	var_Elements:Insert("Child 3","rootID",nil)
	var_Elements:Insert("Sub-Child 1.2","childID",nil)
	var_Elements:Insert("Sub-Child 2.2","childID",nil)

PowerBuilder

OleObject oSurface,var_Elements

oSurface = ole_1.Object
var_Elements = oSurface.Elements
	var_Elements.Add("Root").ID = "rootID"
	var_Elements.Insert("Child 1","rootID")
	var_Elements.Insert("Child 2","rootID").ID = "childID"
	var_Elements.Insert("Child 3","rootID")
	var_Elements.Insert("Sub-Child 1.2","childID")
	var_Elements.Insert("Sub-Child 2.2","childID")

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
		Variant voElement
		Get ComAdd of hoElements "Root" Nothing Nothing to voElement
		Handle hoElement
		Get Create (RefClass(cComElement)) to hoElement
		Set pvComObject of hoElement to voElement
			Set ComID of hoElement to "rootID"
		Send Destroy to hoElement
		Get ComInsert of hoElements "Child 1" "rootID" Nothing to Nothing
		Variant voElement1
		Get ComInsert of hoElements "Child 2" "rootID" Nothing to voElement1
		Handle hoElement1
		Get Create (RefClass(cComElement)) to hoElement1
		Set pvComObject of hoElement1 to voElement1
			Set ComID of hoElement1 to "childID"
		Send Destroy to hoElement1
		Get ComInsert of hoElements "Child 3" "rootID" Nothing to Nothing
		Get ComInsert of hoElements "Sub-Child 1.2" "childID" Nothing to Nothing
		Get ComInsert of hoElements "Sub-Child 2.2" "childID" Nothing to Nothing
	Send Destroy to hoElements
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 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("Root"):ID := "rootID"
			oElements:Insert("Child 1","rootID")
			oElements:Insert("Child 2","rootID"):ID := "childID"
			oElements:Insert("Child 3","rootID")
			oElements:Insert("Sub-Child 1.2","childID")
			oElements:Insert("Sub-Child 2.2","childID")

	oForm:Show()
	DO WHILE nEvent != xbeP_Quit
		nEvent := AppEvent( @mp1, @mp2, @oXbp )
		oXbp:handleEvent( nEvent, mp1, mp2 )
	ENDDO 
RETURN
Copyright 1999-2017 Exontrol. All rights reserved.