sub main()
panel_open_vba();
end sub




sub new_xml()
DIM CPATH AS STR;
DIM EXPRESSION_CPATH AS STR; 
DIM i AS INTEGER; 
DIM hbuffer As Long; 
DIM intvalue As Integer; 
Dim Count As Integer;
 
intvalue = 1000;  
 
hbuffer = ALLOC_BUFFER(intvalue);
PRINT("Buffer handle = ",hbuffer); 
 
 
@Text01=Window("GETCOLLECTION");
print (Window("GETCOLLECTION"));
SEQ_BUFFER("INSERTFIELD", 1, hbuffer, "\0", Window("GETCOLLECTION"));
 
PRINT("LEN ", SEQ_BUFFER("LEN", hbuffer));
 
'PRINT(Cget_Buffer(hbuffer , 40));
'Print("XML Function @text01- ", XMLPATH("LOAD", "CTX1", Text01));
Print("XML Function Buffer- ", XMLPATH("LOAD", "CTX1", hbuffer));
 
'Print(Cget_Buffer(hbuffer, 0));
'print(@Text01);
 
Print("count from function-",XMLPATH("COUNT", "CTX1","Mimics/Mimic"));
@xml.count1 = XMLPATH("GETSTR", "CTX1","Mimics/Count[1]");
Print("count from XLM- ",XMLPATH("GETSTR", "CTX1","Mimics/Count[1]"));
Count = XMLPATH("COUNT", "CTX1","Mimics/Mimic");
@xml.count2=TOD(Count);


 
for (i=1; i<=Count;i++)
EXPRESSION_CPATH="Mimics/Mimic[%i]/Name[1]";
CPATH=FORMAT(EXPRESSION_CPATH,i);
print("Mimic name - ",XMLPATH("GETSTR","CTX1",CPATH));
 
EXPRESSION_CPATH="Mimics/Mimic[%i]/Branch[1]";
CPATH=FORMAT(EXPRESSION_CPATH,i);
print("Branch - ",XMLPATH("GETSTR","CTX1",CPATH));
 
EXPRESSION_CPATH="Mimics/Mimic[%i]/Index[1]";
CPATH=FORMAT(EXPRESSION_CPATH,i);
print("Index - ",XMLPATH("GETSTR","CTX1",CPATH));
 
EXPRESSION_CPATH="Mimics/Mimic[%i]/Left[1]";
CPATH=FORMAT(EXPRESSION_CPATH,i);
print("Left - ",XMLPATH("GETSTR","CTX1",CPATH));
 
EXPRESSION_CPATH="Mimics/Mimic[%i]/Top[1]";
CPATH=FORMAT(EXPRESSION_CPATH,i);
print("Top - ",XMLPATH("GETSTR","CTX1",CPATH));
 
Next
 
@xml.mimicbranch1= XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Branch[1]");
@xml.mimicbranch2= XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Branch[1]");
@xml.mimicbranch3= XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Branch[1]");

@xml.mimicname1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Name[1]");
@xml.mimicname2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Name[1]");
@xml.mimicname3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Name[1]");

@xml.posx1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Left[1]");
@xml.posy1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Top[1]");

@xml.posx2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Left[1]");
@xml.posy2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Top[1]");

@xml.posx3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Left[1]");
@xml.posy3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Top[1]");

@xml.height1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Height[1]");
@xml.width1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Width[1]");
@xml.index1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Index[1]");
@xml.refset1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Refset[1]");
@xml.region1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Region[1]");
@xml.popup1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Popup[1]");
@xml.cache1=XMLPATH("GETSTR","CTX1","Mimics/Mimic[1]/Cache[1]");

@xml.height2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Height[1]");
@xml.width2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Width[1]");
@xml.index2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Index[1]");
@xml.refset2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Refset[1]");
@xml.region2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Region[1]");
@xml.popup2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Popup[1]");
@xml.cache2=XMLPATH("GETSTR","CTX1","Mimics/Mimic[2]/Cache[1]");

@xml.height3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Height[1]");
@xml.width3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Width[1]");
@xml.index3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Index[1]");
@xml.refset3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Refset[1]");
@xml.region3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Region[1]");
@xml.popup3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Popup[1]");
@xml.cache3=XMLPATH("GETSTR","CTX1","Mimics/Mimic[3]/Cache[1]");




 
 
FREE_BUFFER(hbuffer);  
 
end sub

SUB PANEL_OPEN_VBA()
	DIM sWindowToOpen 	AS STR;
	DIM sWindowBranch 	AS STR;
	DIM iWinPosX 		AS INTEGER;
	DIM iWinPosY 		AS INTEGER;
	DIM iExeAni			AS INTEGER;
	
	DIM sParentName 	AS STR;
	DIM sParentBranch 	AS STR;
	
	DIM CPATH AS STR;
	DIM EXPRESSION_CPATH AS STR; 
	DIM i AS INTEGER; 
	DIM hbuffer As Long; 
	DIM intvalue As Integer; 
	Dim Count As INTEGER;
	
	Dim iReturnVal as INTEGER;
	DIM sXmlFileName as STR;
	DIM sXmlFileCorr as STR;
	DIM sXmlFile as STR;
	
	intvalue = 1000;
	
	sParentName 	= Window("CURRENTNAME");
	sParentBranch 	= Window("CURRENTBRANCH");
	sWindowToOpen 	= GetArg("ARG1");
	sWindowBranch 	= GetArg("BRANCH");
	
	iWinPosX = -1;
	iWinPosY = -1;
	
	sXmlFileName = "CTX1";
 
 	'Zum Auslesen der Mimics
	hbuffer = ALLOC_BUFFER(intvalue);
	PRINT("Buffer handle = ",hbuffer); 
	
	print ("TEST: ", Window("GETCOLLECTION"));

	SEQ_BUFFER("INSERTFIELD", 1, hbuffer, "\0", Window("GETCOLLECTION")); 'To receive the XML information about all open mimics in buffer
	'PRINT("TEST: ", "LEN ", SEQ_BUFFER("LEN", hbuffer));
	
	'Information from buffer is loaded into XMLPATH object with the name CTX1. Later CTX1 will be used to extract the needed information(for example, branch) about selected mimic  
	'iReturnVal = XMLPATH("LOAD", sXmlFileName, hbuffer); 
	iReturnVal = XMLPATH("LOAD", sXmlFileName, Window("GETCOLLECTION")); 
	 
	 
	Print("TEST: ", "XMLPATH is loading: ", iReturnVal);
	
	'Maybe dont need
	IF( iReturnVal == -4 ) THEN 'not used, if used than change value -4 to -1
		Print("TEST: ", "ERROR: XMLPATH load not ok");
		
		sXmlFileCorr = Window("GETCOLLECTION");
	
		FOR(i=0; i<4; i++)
			sXmlFile = MID (sXmlFileCorr ,99 + i, 10);
			'print("TEST: ", sXmlFile);
		
			IF (CmpString(sXmlFile, "<Branch />") == 0 ) THEN
				sXmlFile = MID (sXmlFileCorr , 0, 99 + i);
				
				sXmlFile = AddString(MID (sXmlFileCorr , 0, 99 + i), "<Branch>NoBranch</Branch>", MID (sXmlFileCorr , 99 + i + 10, Len(sXmlFileCorr)));
				print("TEST: Ausgebessert", sXmlFile);
				
				iReturnVal = XMLPATH("LOAD", sXmlFileName, sXmlFile);
				Print("TEST: ", "XMLPATH is loading: ", iReturnVal);
			END IF
		NEXT
		'RETURN;
	END IF
	
	'There are few ways of receiving the number of opened mimic. One of them is reading the value from Mimic / Count object. And another one is to use the function XMLPATH("COUNT",.)
	Count = IVAL(XMLPATH("GETSTR", sXmlFileName,"Mimics/Count[1]"));
	Print("TEST: ", "Count from XLM: ", Count);
	
	'Using the number of opened mimic it's possible to read mimics name, index, branch, and top and left coordinates
	'Below is example of using XMLPATH("GETSTR",.)
	for (i=1; i<=Count;i++)
		EXPRESSION_CPATH="Mimics/Mimic[%i]/Name[1]";
		CPATH=FORMAT(EXPRESSION_CPATH,i);
		
		Print("<<< TEST - Mimic: ", i);
		
		print("Name: ",		XMLPATH("GETSTR", sXmlFileName, CPATH));
		
		print("Name: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Name[1]")));
		print("Branch: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Branch[1]")));
		print("Left: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Left[1]")));
		print("Top: ", 		XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Top[1]")));
		print("Height: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Height[1]")));
		print("Width: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Width[1]")));
		print("Index: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Index[1]")));
		print("Refset: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Refset[1]")));
		print("Region: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Region[1]")));
		print("Popup: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Popup[1]")));
		print("Cache: ", 	XMLPATH("GETSTR", sXmlFileName, AddString("Mimics/Mimic[", TOC(i), "]/Cache[1]")));
		Print(" >>>");
						
		'Compare of Mimic names
		IF (CmpString(sParentName, XMLPATH("GETSTR",sXmlFileName,CPATH)) == 0 ) THEN
			EXPRESSION_CPATH="Mimics/Mimic[%i]/Branch[1]";
			CPATH=FORMAT(EXPRESSION_CPATH,i);
			print("TEST: ", "Branch - ",XMLPATH("GETSTR",sXmlFileName,CPATH));
			
			'Compare of branches
			IF (CmpString(sParentBranch, XMLPATH("GETSTR",sXmlFileName,CPATH)) == 0 ) THEN

				EXPRESSION_CPATH="Mimics/Mimic[%i]/Left[1]";
				CPATH=FORMAT(EXPRESSION_CPATH,i);
				print("TEST: ", "Left - ",XMLPATH("GETSTR",sXmlFileName,CPATH));
				
				iWinPosX = TOI(XMLPATH("GETSTR",sXmlFileName,CPATH)) + 200;
				
				
				EXPRESSION_CPATH="Mimics/Mimic[%i]/Top[1]";
				CPATH=FORMAT(EXPRESSION_CPATH,i);
				print("TEST: ", "Top - ",XMLPATH("GETSTR",sXmlFileName,CPATH));
				
				iWinPosY = TOI(XMLPATH("GETSTR",sXmlFileName,CPATH));
				
			END IF
		END IF	
	Next

	'IF one of the Position Values still not changed
	IF( iWinPosX < 0 || iWinPosY < 0 ) THEN
		'FREE_BUFFER(hbuffer);
		return;
	END IF

	iExeAni = 0;
			
		IF (CmpString(sWindowToOpen, "XFAB_ERF/Panel_INFO") == 0 ) THEN
			IF (VARIABLE ("STATUS", sWindowBranch, "EXIST") == 0) THEN
				IF (VARIABLE ("STATUS", AddString(sWindowBranch, ".PA"), "EXIST") == 1) THEN
					sWindowBranch = AddString(sWindowBranch, ".PA");
					iExeAni = 1;
				END IF
			END IF
		END IF
	
		WINDOW("OPEN", sWindowToOpen, sWindowBranch, "", "", iWinPosX, iWinPosY);
		
		IF ( iExeAni == 1 ) THEN
			ANIMATION("EXECUTE", Window("CURRENTNAME"), Window("CURRENTBRANCH"), "ADMIN");
		END IF

	
	FREE_BUFFER(hbuffer);  
	
	
	'@APPLIKATION.MIMICMANAGEMENT.PANELS.MimicToOpen  = GetArg("ARG1");
	'@APPLIKATION.MIMICMANAGEMENT.PANELS.MimicBranch = GetArg("BRANCH");
	'@APPLIKATION.MIMICMANAGEMENT.PANELS.tGetPosition = 1;
END SUB

