Copy Data Structure

6 views
Skip to first unread message

willi...@gmail.com

unread,
May 18, 2009, 8:50:23 AM5/18/09
to FBDK
Hi Jim

I'm working on a update FB which keep a Data structure internally as
internal variable and you can update data in or read data out from
this block. But I found if using express like that in the algorithms
to copy data out like DataStructureInstance1 = DataStructureInstance2
cannot copy value out. Also If there is a data structure inside a data
structure, even you use
DataStructure1Instance1.DataStructure2.VariableName.Value =
DataStructure1Instance2.DataStructure2.VariableName.Value to assign a
value. Is there an easier way to doing that? Thanks a lot.

Best Regards,
William Dai

James Christensen

unread,
May 18, 2009, 9:31:44 AM5/18/09
to fb...@googlegroups.com
Try DataStructureInstance1.copyFrom(DataStructureInstance2). That
should do a deep copy.
- Jim C
--
Best regards,
Jim Christensen

William Dai

unread,
May 19, 2009, 6:02:50 AM5/19/09
to fb...@googlegroups.com
Hi Jim

Thanks for your reply. I tried to use copyFrom it works. But when it
tried to copy a STRING type data in the data structure, it failed.

My Data structure contains:INT, STRING, and Data structure inside Data
structure.

I initialize my STRING type with .value = null. and copyFrom() only
copied first element in the Data structure of Data structure. Rest of
the data still 0s or null. Have you got any idea? Thanks a lot.
--
Best Regards,
William Dai

Jim Christensen

unread,
May 19, 2009, 9:46:17 AM5/19/09
to FBDK
Don't initialize STRING values to null. STRINGs contain an array of
bytes initialized to 8-bit character values, and trying to copy a null
value will abort the copy operation. The correct way to initialize a
STRING is:

aSTRING.initialize("\'Some initialization string\'");

The contained single-quote delimiters are mandatory, but will not be
copied to the internal byte array.

If you want to have just a normal Java String as the value then use
WSTRING. Then you can say

aWSTRING.value = ("Another initialization string");

See the difference?

On May 19, 6:02 am, William Dai <william...@gmail.com> wrote:
> Hi Jim
>
> Thanks for your reply. I tried to use copyFrom it works. But when it
> tried to copy a STRING type data in the data structure, it failed.
>
> My Data structure contains:INT, STRING, and Data structure inside Data
> structure.
>
> I initialize my STRING type with .value = null. and copyFrom() only
> copied first element in the Data structure of Data structure. Rest of
> the data still 0s or null. Have you got any idea? Thanks a lot.
>
> On Tue, May 19, 2009 at 1:31 AM, James Christensen
>
>
>
> <james.h.christen...@gmail.com> wrote:
>
> > Try DataStructureInstance1.copyFrom(DataStructureInstance2). That
> > should do a deep copy.
> > - Jim C
>

Jim Christensen

unread,
May 19, 2009, 9:51:40 AM5/19/09
to FBDK
Oops, should have said
aWSTRING.value = "Another initialization string";
- Jim C
On May 19, 9:46 am, Jim Christensen <james.h.christen...@gmail.com>
wrote:

William Dai

unread,
May 20, 2009, 7:30:40 AM5/20/09
to fb...@googlegroups.com
Hi Jim

Thanks for your help. It works perfect now.
Reply all
Reply to author
Forward
0 new messages