[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.axapta.programming

How to get access to the form datasource with a form control handl

Luegisdorf

10/26/2005 9:03:00 AM

Hi everyone

On a form exists a control boundet to a existing data source and data field.
At runtime I want to access the form data source with the handle of the
control.

I tried this, but I doesn't get a valid form data source object:

formDataSource = formRun.dataSource(myBoundStringControl.dataSource());
// after that formDataSource is still null

What's wrong in here. Can you help me?

Thank you in advance.
Best regards
Patrick

6 Answers

Anton Venter

10/26/2005 10:21:00 AM

0

Try the following:
formDataSource = formRun.dataSource();

"Luegisdorf" <Luegisdorf@discussions.microsoft.com> wrote in message
news:4E228DCA-D728-4B27-BE09-BEBF663CD3DC@microsoft.com...
> Hi everyone
>
> On a form exists a control boundet to a existing data source and data
> field.
> At runtime I want to access the form data source with the handle of the
> control.
>
> I tried this, but I doesn''t get a valid form data source object:
>
> formDataSource = formRun.dataSource(myBoundStringControl.dataSource());
> // after that formDataSource is still null
>
> What''s wrong in here. Can you help me?
>
> Thank you in advance.
> Best regards
> Patrick
>


Luegisdorf

10/26/2005 10:35:00 AM

0

Hi Anton

There''s the problem that my form can have more than one dataSource and I
need exactly the dataSource which the form control is using.

Any other ideas?

"Anton Venter" wrote:

> Try the following:
> formDataSource = formRun.dataSource();
>
> "Luegisdorf" <Luegisdorf@discussions.microsoft.com> wrote in message
> news:4E228DCA-D728-4B27-BE09-BEBF663CD3DC@microsoft.com...
> > Hi everyone
> >
> > On a form exists a control boundet to a existing data source and data
> > field.
> > At runtime I want to access the form data source with the handle of the
> > control.
> >
> > I tried this, but I doesn''t get a valid form data source object:
> >
> > formDataSource = formRun.dataSource(myBoundStringControl.dataSource());
> > // after that formDataSource is still null
> >
> > What''s wrong in here. Can you help me?
> >
> > Thank you in advance.
> > Best regards
> > Patrick
> >
>
>
>

Mike Oakes

10/26/2005 10:09:00 PM

0

try this

formBuildDataSource formBuildDataSource;
FormBuildStringControl FormBuildStringControl ;
;
FormBuildStringControl = _control;

formBuildDataSource =
formRun.form().dataSource(formBuildStringControl.dataSource());


--
Kind Regards

Michael Oakes


"Luegisdorf" wrote:

> Hi everyone
>
> On a form exists a control boundet to a existing data source and data field.
> At runtime I want to access the form data source with the handle of the
> control.
>
> I tried this, but I doesn''t get a valid form data source object:
>
> formDataSource = formRun.dataSource(myBoundStringControl.dataSource());
> // after that formDataSource is still null
>
> What''s wrong in here. Can you help me?
>
> Thank you in advance.
> Best regards
> Patrick
>

DouglasT

10/27/2005 2:03:00 PM

0

i use to prefer the following

static FormDataSource GetFDSFromControl(FormControl _fc)
{
int datasourceIDCtrl;
ClassID ctrlID;
DictClass dc;
int iCnt;
int i;
int ifrCnt;
int ifr;
FormDataSource ret;
FormObjectSet fobjset;
FormDataSource fds2;
FormStringControl xx;
boolean bHasDataSourceMth = FALSE;
FormRun fr;
Object obj;
;
if (_fc) {
obj = _fc.owner();
if ((obj) && (SysDictClass::isEqualOrSuperclass(classIDget(obj),
classnum(FormRun)))) {
fr = obj;
ctrlID = classIDget(_fc);
if (ctrlID) {
dc = new DictClass(ctrlID);
if (dc) {
iCnt = dc.objectMethodCnt();
for (i=1;i<=iCnt;i++) {
if ( dc.objectMethod(i) == ''dataSource'' ) {
bHasDataSourceMth = TRUE;
break;
}
}
if (bHasDataSourceMth) {
datasourceIDCtrl = dc.callObject(''dataSource'', _fc);
if (datasourceIDCtrl) {
ifrCnt = fr.dataSourceCount();
for (ifr=1;ifr<=ifrCnt;iFr++) {
fobjset = fr.dataSource(ifr);
if ((fobjset) &&
(SysDictClass::isEqualOrSuperclass(classidget(fobjset),
classnum(FormDataSource)))) {
fds2 = fobjSet;
if ( fds2.id() == datasourceIDCtrl) {
ret = fds2;
break;
}
}
}
}
}
}
}
}
}
return ret;
}

regards douglas


"Luegisdorf" <Luegisdorf@discussions.microsoft.com> schrieb im Newsbeitrag
news:4E228DCA-D728-4B27-BE09-BEBF663CD3DC@microsoft.com...
> Hi everyone
>
> On a form exists a control boundet to a existing data source and data
> field.
> At runtime I want to access the form data source with the handle of the
> control.
>
> I tried this, but I doesn''t get a valid form data source object:
>
> formDataSource = formRun.dataSource(myBoundStringControl.dataSource());
> // after that formDataSource is still null
>
> What''s wrong in here. Can you help me?
>
> Thank you in advance.
> Best regards
> Patrick
>


Luegisdorf

10/28/2005 6:23:00 AM

0

Hi Mike

Thank you for your input:

Now I know what was wrong with my code!

The wrong way: formRun.dataSource(control.dataSource) - you will get ever a
null pointer

The right way: formRun.form().dataSource(control.dataSource) - you get the
right object

Thank you very much!

Best regards
Patrick


"Mike Oakes" wrote:

> try this
>
> formBuildDataSource formBuildDataSource;
> FormBuildStringControl FormBuildStringControl ;
> ;
> FormBuildStringControl = _control;
>
> formBuildDataSource =
> formRun.form().dataSource(formBuildStringControl.dataSource());
>
>
> --
> Kind Regards
>
> Michael Oakes
>
>
> "Luegisdorf" wrote:
>
> > Hi everyone
> >
> > On a form exists a control boundet to a existing data source and data field.
> > At runtime I want to access the form data source with the handle of the
> > control.
> >
> > I tried this, but I doesn''t get a valid form data source object:
> >
> > formDataSource = formRun.dataSource(myBoundStringControl.dataSource());
> > // after that formDataSource is still null
> >
> > What''s wrong in here. Can you help me?
> >
> > Thank you in advance.
> > Best regards
> > Patrick
> >

Luegisdorf

10/28/2005 6:29:00 AM

0

Hi Douglas

Thank you for your script; This way I tried too, but comparing
formRun.dataSource() with control.dataSource() never match (the control''s
dataSourceNo is about 1 up to 3 and the formRun''s dataSource was 1228 and
higher).

I use now formRun.form().dataSource(control.dataSource()) as Mike has
suggested and it works well. Of course I check before if the control is a
data control or not to prevent from ugly exceptions.

Thank you for your answer
Best regards
Patrick
"DouglasT" wrote:

> i use to prefer the following
>
> static FormDataSource GetFDSFromControl(FormControl _fc)
> {
> int datasourceIDCtrl;
> ClassID ctrlID;
> DictClass dc;
> int iCnt;
> int i;
> int ifrCnt;
> int ifr;
> FormDataSource ret;
> FormObjectSet fobjset;
> FormDataSource fds2;
> FormStringControl xx;
> boolean bHasDataSourceMth = FALSE;
> FormRun fr;
> Object obj;
> ;
> if (_fc) {
> obj = _fc.owner();
> if ((obj) && (SysDictClass::isEqualOrSuperclass(classIDget(obj),
> classnum(FormRun)))) {
> fr = obj;
> ctrlID = classIDget(_fc);
> if (ctrlID) {
> dc = new DictClass(ctrlID);
> if (dc) {
> iCnt = dc.objectMethodCnt();
> for (i=1;i<=iCnt;i++) {
> if ( dc.objectMethod(i) == ''dataSource'' ) {
> bHasDataSourceMth = TRUE;
> break;
> }
> }
> if (bHasDataSourceMth) {
> datasourceIDCtrl = dc.callObject(''dataSource'', _fc);
> if (datasourceIDCtrl) {
> ifrCnt = fr.dataSourceCount();
> for (ifr=1;ifr<=ifrCnt;iFr++) {
> fobjset = fr.dataSource(ifr);
> if ((fobjset) &&
> (SysDictClass::isEqualOrSuperclass(classidget(fobjset),
> classnum(FormDataSource)))) {
> fds2 = fobjSet;
> if ( fds2.id() == datasourceIDCtrl) {
> ret = fds2;
> break;
> }
> }
> }
> }
> }
> }
> }
> }
> }
> return ret;
> }
>
> regards douglas
>
>
> "Luegisdorf" <Luegisdorf@discussions.microsoft.com> schrieb im Newsbeitrag
> news:4E228DCA-D728-4B27-BE09-BEBF663CD3DC@microsoft.com...
> > Hi everyone
> >
> > On a form exists a control boundet to a existing data source and data
> > field.
> > At runtime I want to access the form data source with the handle of the
> > control.
> >
> > I tried this, but I doesn''t get a valid form data source object:
> >
> > formDataSource = formRun.dataSource(myBoundStringControl.dataSource());
> > // after that formDataSource is still null
> >
> > What''s wrong in here. Can you help me?
> >
> > Thank you in advance.
> > Best regards
> > Patrick
> >
>
>
>