(My first post – I’m delighted to join the community…)
I have a custom form. No datasources are assigned to the form in AOT. I’d like to add various form datasources to the form at runtime depending on certain conditions.
I’ve learned from the MSDN documentation that I can add a datasource to form if the form is created from code – I used http://msdn.microsoft.com/en-us/library/formrun.datasource.aspx as an example:
After creating the form
form = new Form() )
I can use
formBuildDataSource = form.addDataSource(dictTable.name());
to add a datasource, retrieving a FormBuildDataSource object for which I can set the table ID.
As the last lines of the example show, after creating a FormRun object, running and detaching it, I can access this datasource (as a FormDataSource object):
// Create the run-time form.
formRun = new FormRun(Args);
formRun.run();
formRun.detach();
// Return an object for the first data source ...
formdatasource = formRun.dataSource(1);
So, this is fine for me: I can access a form data source as FormDataSource object if I add the datasource as FormBuildDataSource to the form beforme FormRun is instantiated.
But what about adding a datasource dynamically to an AOT-based form which is not created from code but defined in AOT and to be modified from code at startup?
Apparently it is not possible to add a form datasource to a form / FormRun during runtime, isn’t it?
I tried to add statements to the form’s code:
formBuildDataSource = this.form().addDataSource(‘MyTestDataSource’);
formBuildDataSource.table(tablenum(MyTestTable));
but no matter where I put them, either in the form’s overridden init() method after super() call or in the form’s run() method before the super() call, I’m not able to create a FormDataSource object.
If I count the form build data sources:
fbdsCount = this.form().dataSourceCount(); // → gives count=1;
If I count form data sources
fdsCount = this.dataSourceCount(); // → gives count=0
No matter where I try to access the newly added form datasource, even at the end of my (overridden) run() method,
formdatasource = this.dataSource(1); // returns null
So there is no form datasource created, even if I added a form build data source to the form.
What am I doing wrong?
Or is it impossible to add a form datasource that way, because I do all my operations inside init() or run() which means after the FormRun has been instantiated?
Is there any means to add a form data source dynamically to a running form (FormRun instantiated) which is defined in AOT?
Any suggestions appreciated.
Many thanks in advance,
- ruhr42