FoxPro Programming
Object.ADD( Obj ) overwritten, WTF?
Gravatar is a globally recognized avatar based on your email address. Object.ADD( Obj ) overwritten, WTF?
  Harvey Mushman
  All
  Jan 10, 2017 @ 02:59pm
oCollection = createobject('collection')
oEmpty = createobject('Empty')

addProperty(oEmpty,'mVar','')
oEmpty.mVar = 'string'
oCollection.Add(oEmpty)
oEmpty.mVar = ''

? oCollection(1)

Displays: mVar = ''


  1. Why would setting mVar='' (empty string) effect the results of the object added to the collection?

  2. What is the work-around to make the object added to the collection an independant from the local object?

If this was Angular a deep copy would be required, but this is VFP the User Friendly programming language!

Gravatar is a globally recognized avatar based on your email address. re: Object.ADD( Obj ) overwritten, WTF?
  Carl Chambers
  Harvey Mushman
  Jan 10, 2017 @ 08:08pm

Hi Harvey,

Here's a fox wikis discussion you may find helpful.

Carl

Gravatar is a globally recognized avatar based on your email address. re: Object.ADD( Obj ) overwritten, WTF?
  Harvey Mushman
  Carl Chambers
  Jan 10, 2017 @ 09:19pm

Thanks, very helpful!

Now I understand what Rick wrote CopyObject...

Gravatar is a globally recognized avatar based on your email address. re: Object.ADD( Obj ) overwritten, WTF?
  FoxInCloud Support - Thierry N.
  Harvey Mushman
  Jan 11, 2017 @ 12:00am

any OOP language behaves the same:

var o = {}
var a = [o]
o['test'] = 'test'
console.log(a) // [Object { test="test"}]

being a framework, AngularJS may have implemented a 'clone object' method that you call 'deep copy'; any JS frameWork offers such a method.

© 1996-2024