Update cookies preferences
Promotic

Příklad: Vytvoří PmForm okno nakonfigurované jako seznam všech proměnných a jejich hodnot v grafických objektech v obrazu.

V jednom skriptu (např. po stisknutí tlačítka v události onButtonUp) se vytvoří uživatelské okno s tabulkou obsahující cestu ke grafickému objektu a seznam proměnných a jejich hodnot.
JavaScriptVyber a zkopíruj do schránky

//#pragma variable sPathDir = Macro("$.path('temp')");
var oForm, oTable, oTabArea, iItem1, iItem2, iItem3, iVar1, iVar2, iVar3;
function LogAdd(aLog)
{
var nRowsMax = 200;
var nRows = oTabArea.RowCount;

oTable.InsertRow(1, -1);
oTabArea.GetRow(nRows).GetCell(0).Value = aLog.GetItem(0);
oTabArea.GetRow(nRows).GetCell(1).Value = aLog.GetItem(1);
if (nRowsMax < nRows)
{
oTable.DeleteRow(1, 0);
}
}

function ClearLog(ev)
{
oTable.DeleteRow(1, 0, oTabArea.RowCount);
}

function SaveLog(ev)
{
var nRows = oTabArea.RowCount;
var sTxtLog = "";
var iRow;
for (iRow = 0; iRow < nRows; iRow++)
{
var oRow = oTabArea.GetRow(iRow);
sTxtLog += oRow.GetCell(0).Value + " | " + oRow.GetCell(1).Value + "\\n";
}
var oCreator = Pm.CreateView(null, "/#glob/form", "", "target:_blank;modal:1;pos:view," + pMe.ViewX + "," + pMe.ViewY);
oCreator.View.onLoad = function(ev)
{
var oFormSave = ev.Form;
oFormSave.Title = "Save log to file";
var oStrDir = oFormSave.CreateItem("string", "dir", "Dir", "Subtype:static;");
oStrDir.Value = sPathDir;
var StrFile = oFormSave.CreateItem("string", "file", "File");
StrFile.Value = "TextLog.txt";

oFormSave.AddEvent("onClose", "butvars", function(ev) { if (ev.CloseReason == "ok") { var bSave = Pm.FileTextWrite("#temp:" + StrFile.Value, sTxtLog, "charset:utf-8;"); if (!bSave) { Pm.MessageBox("Save Log Error", "Save Log to file:\\n" + sPathDir + StrFile.Value + "\\n\\nfailed !!!"); } } });
};
oCreator.Open();
}


function ReadVars(ev)
{
var sVars;
var nChildCount = pMe.Root.GetChildCount();
var nCount0 = pMe.Root.GetVarCount();
// PmgRoot variables
if (nCount0 > 0)
{
sVars = "";
for (iVar1 = 0; iVar1 < nCount0; iVar1++)
{
sVars += pMe.Root.Vars(iVar1).Name + "=" + pMe.Root.Vars(iVar1).Value + "; ";
}
LogAdd(Pm.CreatePmArray().Array1("Root", sVars));
}
for (iItem1 = 0; iItem1 < nChildCount; iItem1++)
{
var oObject1 = pMe.Root.GetChildByIndex(iItem1);
// 1. Start Level
var nCount1 = oObject1.GetVarCount();
if (nCount1 > 0)
{
sVars = "";
for (iVar1 = 0; iVar1 < nCount1; iVar1++)
{
sVars += oObject1.Vars(iVar1).Name + "=" + oObject1.Vars(iVar1).Value + "; ";
}
LogAdd(Pm.CreatePmArray().Array1("/" + oObject1.Name, sVars));
}
// End 1. Level

// 2. Start Level
var nChildCount2 = oObject1.GetChildCount();
for (iItem2 = 0; iItem2 < nChildCount2; iItem2++)
{
var oObject2 = oObject1.GetChildByIndex(iItem2);
var nCount2 = oObject2.GetVarCount();
if (nCount2 > 0)
{
sVars = "";
for (iVar2 = 0; iVar2 < nCount2; iVar2++)
{
sVars += oObject2.Vars(iVar2).Name + "=" + oObject2.Vars(iVar2).Value + "; ";
}
LogAdd(Pm.CreatePmArray().Array1("/" + oObject1.Name + "/" + oObject2.Name, sVars));
}

// Start 3. Level
var nChildCount3 = oObject2.GetChildCount();
for (iItem3 = 0; iItem3 < nChildCount3; iItem3++)
{
var oObject3 = oObject2.GetChildByIndex(iItem3);
var nCount3 = oObject3.GetVarCount();
if (nCount3 > 0)
{
sVars = "";
for (iVar3 = 0; iVar3 < nCount3; iVar3++)
{
sVars += oObject3.Vars(iVar3).Name + "=" + oObject3.Vars(iVar3).Value + "; ";
}
LogAdd(Pm.CreatePmArray().Array1("/" + oObject1.Name + "/" + oObject2.Name + "/" + oObject3.Name, sVars));
}
}
}
}
}

function onFormLoad(ev)
{
var oForm = ev.Form;
oForm.Title = "Read PmgVars";
oForm.SysLayoutPos = "bottom";

oForm.SysButtons = "cancel";
var oButt;
var oButtLay = oForm.GetItem("$sys", 1);

// button READ Vars
oButt = oButtLay.CreateItem("button", "buttVars");
oButt.Value = "Read Vars";
oButt.AddEvent("onAction", "butvars", ReadVars);

// button CLEAR LOG
oButt = oButtLay.CreateItem("button", "buttClear");
oButt.Value = "Clear Log";
oButt.AddEvent("onAction", "clearlog", ClearLog);

// button SAVE LOG
oButt = oButtLay.CreateItem("button", "buttSave");
oButt.Value = "Save Log";
oButt.AddEvent("onAction", "savelog", SaveLog);

// ----------- TABLE -----------------
oTable = oForm.CreateItem("table", "idTable");
oTable.InitRows(0, 1, 0);
oTable.InitCols(2, 0);

// TableArea 11=MainBody
oTabArea = oTable.GetArea(11);
oTabArea.BgColor = "#ffffff";
oTabArea.HorzAlign = "left";
oTable.SetColWidth(12, 1, 0, 1);
oTable.SetColWidth(28, 1, 1, 1);
var oTabHead = oTable.GetArea(12);
oTabHead.GetRow(0).GetCell(0).Value = "Path:";
oTabHead.GetRow(0).GetCell(1).Value = "Vars and values:";
ReadVars();
}

var sFramePars = "target:_blank;pos:view," + pMe.ViewX + "," + pMe.ViewY + ";size:500,500;";
var oCreator = Pm.CreateView(null, "/#glob/form", "", sFramePars);
oCreator.View.onLoad = onFormLoad;
oCreator.Open();
© MICROSYS, spol. s r.o.