[Openroad-users] Accessing dynamically created fields
Bodo Bergmann
Bodo.Bergmann at ingres.com
Wed Sep 5 19:31:45 EST 2007
Here is an example, where
- "field2" is created as duplicate of "field1", which is an EntryField
on the form.
- "m1", "m2" and "m3" are created as duplicates of "m", which is a
MatrixField on the form,
containg entryfield "a1" and having the DataType set to userclass
aUserClass (which has attribute a1).
The parent of the dynamically created MatrixFields will be the
StackField "sf",
which has the "Declared" attribute set to FALSE.
initialize()=
declare
ef = EntryField DEFAULT NULL;
dexp = DynExpr DEFAULT NULL;
mf = MatrixField DEFAULT NULL;
aObject = aUserClass DEFAULT NULL;
i=INTEGER NOT NULL;
enddeclare
{
CurFrame.Trace(text='Start.');
ef = FIELD(field1).Duplicate();
ef.Name = 'field2';
ef.XLeft=0;
ef.YTop=0;
ef.ParentField = CurFrame.TopForm;
ef.SetFieldValue(value='abc');
ef.DeclareData();
dexp = CurFrame.Scope.CreateDynExpr(String='field2');
IF dexp IS NOT NULL THEN
dexp.SetValue(value='xyz');
ENDIF;
FOR i=1 TO 3
DO
mf = FIELD(m).Duplicate();
mf.Name = 'm'+varchar(i);
mf.XLeft=0;
mf.YTop=0;
FIELD(sf).InsertChild(fieldtoinsert=mf, position=i);
ENDFOR;
// This will declare data for all child fields as well:
FIELD(sf).DeclareData();
FOR i=1 TO 3
DO
dexp = CurFrame.Scope.CreateDynExpr(String='sf.m'+varchar(i));
IF dexp IS NOT NULL THEN
aObject = aUserClass.Create();
aObject.a1 = 'blabla'+varchar(i);
dexp.SetValue(value=aObject);
ENDIF;
ENDFOR;
}
The value of field2 will be 'xyz', if you don't DeclareData() the value
is 'abc';
The values of "a1" in the 3 created MatrixFields are 'blabla1',
'blabla2' and 'blabla3', resp.
That is, the DynExpr is working perfectly.
Other comments:
"When I attached the field to CurFrame.TopForm, the DeclareData() works
but the DynExpr still fails."
Could you explain what fails: CreateDynExpr() or
DynExpr.SetValue() ?
"When I created the field and attached it to the StackField,
DeclareData() said that '... the field is part of a named field ...'."
Does your grouping StackField or your viewport around it have a
name?
If this is the case then the DynExpr you created using:
ExprPtr =
CurFrame.Scope.CreateDynExpr(String='r'+RIGHT('000'+VARCHAR(i),3)))
wouldn't work anyway, because the correct expression is then
<parentname>+'.'+fieldname.
The error message already explains what's going on:
In this case you have to use DeclareData() on the named parent
rather than the dynamic field
(see in my example above: DeclareData is done on "sf" rather
than on the inserted MatrixField).
Hope this helps,
Bodo.
Bodo Bergmann
Senior Software Engineer
OpenROAD Worldwide Development
Ingres Corp.
-----Original Message-----
From: openroad-users-bounces at peerlessit.com
[mailto:openroad-users-bounces at peerlessit.com] On Behalf Of James Higson
Sent: Wednesday, September 05, 2007 12:15 AM
To: 'International OpenROAD Users'
Subject: Re: [Openroad-users] Accessing dynamically created fields
Using DeclareData() did not work. When I created the field and attached
it
to the StackField, DeclareData() said that "... the field is part of a
named
field ...". When I attached the field to CurFrame.TopForm, the
DeclareData() works but the DynExpr still fails.
-----Original Message-----
From: openroad-users-bounces at peerlessit.com
[mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Bodo
Bergmann
Sent: Wednesday, 5 September 2007 04:00
To: International OpenROAD Users
Subject: Re: [Openroad-users] Accessing dynamically created fields
You are right.
The dynamic expression just doesn't work as long as you didn't declare
it's
data, as there is no data item with the according name.
So an option is to use:
FieldPtr.DeclareData();
before creating the DynExpr.
I didn't do this as James mentioned, that he wanted to set the value of
the
field to an already existing object (in an array), so I'had seen no
reason
to create an object by DeclareData(), which is then released anyway.
Bodo.
Bodo Bergmann
Senior Software Engineer
OpenROAD Worldwide Development
Ingres Corp.
-----Original Message-----
From: openroad-users-bounces at peerlessit.com
[mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Simon Lovell
Sent: Monday, September 03, 2007 11:29 PM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Accessing dynamically created fields
Isn't that because the declared attribute is effectively set to FALSE
for
dynamically created fields? Wouldn't another option be to use the
.DeclareData() method? Not sure if you can map the field to an
attribute of
an array though, and that's the only way it would be useful.
Bodo Bergmann wrote:
> James,
>
> you can't reference the dynamically created fields using dynamic
> expressions.
>
> But anyway you can use the FieldByFullName approach to set the value
> of the field:
> FieldPtr =
>
CurFrame.TopForm.FieldByFullName(FullName='r'+RIGHT('000'+VARCHAR(i),3))
);
> FieldPtr.SetFieldValue(value = a[i]);
>
> Bodo.
>
> Bodo Bergmann
> Senior Software Engineer
> OpenROAD Worldwide Development
> Ingres Corp.
>
>
>
------------------------------------------------------------------------
> *From:* openroad-users-bounces at peerlessit.com
> [mailto:openroad-users-bounces at peerlessit.com] *On Behalf Of *James
Higson
> *Sent:* Monday, September 03, 2007 12:52 AM
> *To:* 'International OpenROAD Users'
> *Subject:* [Openroad-users] Accessing dynamically created fields
>
> Hi all,
>
> I am using OR4.1SP3.
>
> I have a StackField object which has a datatype of a userclass. I
> have then created several instances of this StackField and grouped
> them into a second StackField then grouped this into a ViewPort. In
> effect, I have mimmicked a TableField. I am then dynamically
> appending instances of the first StackField to the second StackField
> by duplicating the first instance at runtime. I hope you are
> following me so far. The instances are then named r001, r002, ...
> r00n.
>
> I can reference the instances by using either:
> FieldPtr =
>
CurFrame.TopForm.FieldByFullName(FullName='r'+RIGHT('000'+VARCHAR(i),3))
),
> or;
> ExprPtr =
> CurFrame.Scope.CreateDynExpr(String='r'+RIGHT('000'+VARCHAR(i),3))).
>
> The problem I have, is that CreateDynExpr only works for the instances
> of the StackField that were statically created on the form. The
> dynamically created instances return a NULL reference.
> FieldByFullName works for the dynamically created instances. I want
> to set the instances to a row in an array by using:
> ExprPtr =
> CurFrame.Scope.CreateDynExpr(String='r'+RIGHT('000'+VARCHAR(i),3)));
> ExprPtr.SetValue(Value = a[i]);
>
> I would have thought that CreateDynExpr should work for dynamically
> created instances as well. Can anyone see another way to do this?
>
> Thanks,
> James
> Melbourne, Australia
>
>-----------------------------------------------------------------------
-
>
>________________________________________________________________
>OpenROAD-Users mailing list
>
>You can maintain your subscription here:
>http://www.peerlessit.com/mailman/listinfo/openroad-users
>
>To unsubscribe click on this link
>mailto:openroad-users-unsubscribe at peerlessit.com&subject=unsubscribe
>
>To subscribe click on this link
>mailto:openroad-users-subscribe at peerlessit.com&subject=subscribe
>
>-----------------------------------------------------------------------
-
>
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.484 / Virus Database: 269.13.2/985 - Release Date:
2/09/2007 4:32 PM
>
>
________________________________________________________________
OpenROAD-Users mailing list
You can maintain your subscription here:
http://www.peerlessit.com/mailman/listinfo/openroad-users
To unsubscribe click on this link
mailto:openroad-users-unsubscribe at peerlessit.com&subject=unsubscribe
To subscribe click on this link
mailto:openroad-users-subscribe at peerlessit.com&subject=subscribe
________________________________________________________________
OpenROAD-Users mailing list
You can maintain your subscription here:
http://www.peerlessit.com/mailman/listinfo/openroad-users
To unsubscribe click on this link
mailto:openroad-users-unsubscribe at peerlessit.com&subject=unsubscribe
To subscribe click on this link
mailto:openroad-users-subscribe at peerlessit.com&subject=subscribe
________________________________________________________________
OpenROAD-Users mailing list
You can maintain your subscription here:
http://www.peerlessit.com/mailman/listinfo/openroad-users
To unsubscribe click on this link
mailto:openroad-users-unsubscribe at peerlessit.com&subject=unsubscribe
To subscribe click on this link
mailto:openroad-users-subscribe at peerlessit.com&subject=subscribe
More information about the Openroad-users
mailing list