Hi, I want to call a form but would like to send its data source and columns to display to it as parameters so that it can then be set at “on show”. how can i do that? help plz.
You cannot set a datasource in the onShow of a form. You need to set it (from the solutionModel) before the form is loaded…
Are you by any chance a developer with a Visual FoxPro background? What you have to realize is that all forms are initialized at application startup and are shown or hidden instead of initialized and destroyed. If you want you can create a form from scratch and do whatever you like. This for example is a BROWSE function that will create a BROWSE like form for any dataset that you feed it.
function browse(ds) {
// create an in memory dataSource
var tmpDataSource = ds.createDataSource('temp');
// create a form
var frmBrowse = solutionModel.newForm('Browse',tmpDataSource,null,true,460,600);
frmBrowse.view = JSForm.LOCKED_TABLE_VIEW;
// add fields
var fieldPos = 0;
for (var i = 1; i <= ds.getMaxColumnIndex(); i++)
{
// get column name
var colName = ds.getColumnName(i)
// determine column width
var colArray = ds.getColumnAsArray(i);
var colWidth=50
for (item in colArray) {
colWidth = Math.max(colWidth,colArray[item].length*10);
}
if (colWidth > 250) {
colWidth=250;
}
// add column
var fld = frmBrowse.newTextField(colName,fieldPos,0,colWidth,20);
fld.titleText = colName;
// determine next field position
fieldPos = fieldPos + colWidth;
}
// show form as a modal popup
var win = application.createWindow("BrowseWindow", JSWindow.MODAL_DIALOG);
forms['Browse'].controller.show(win);
// cleanup
solutionModel.removeForm('Browse');
}
function test() {
var ds = databaseManager.createEmptyDataSet();
ds.addColumn('country_id');
ds.addColumn('country_code');
ds.addColumn('country_name');
ds.addColumn('country_english');
// add data
ds.addRow([31, 'NL', 'Nederland', 'The Netherlands']);
ds.addRow([32, 'B', 'België', 'Belgium']);
ds.addRow([33, 'F', 'France', 'France']);
ds.addRow([49, 'D', 'Deutschland', 'Germany']);
globals.browse(ds);
}
thanks, very interesting idea! Didnt think of doing it this way.