Hi Mike,
Appended is a function to do this (digged out of our library, I hope
without dependency).
I have an interesting story about cloning objects
In JavaScript, Arrays are objects; it does that:
var a = [0,1], b= new Array;
b = a;
a[1] = 2;
b[1] === 2 /* true */
to copy an Array to another fresh Array, you need to write
b = a.slice(0);
instead of
b = a;
* ========================================
FUNCTION oClone && {en} Clones an object {fr} Clone un objet
LPARAMETERS toObj AS Collection && or whatever, just for intellisense
LOCAL loResult AS Collection; && or whatever
, llResult as Boolean;
, laProp[1], lcProp, luProp;
, liItem, lcKey;
, lnRow, lnCol;
loResult = m.toObj
IF Vartype(m.toObj) == 'O'
loResult = Iif(Type('m.toObj.Class') == 'U';
, CreateObject('Empty');
, NewObject(m.toObj.Class, m.toObj.ClassLibrary);
)
IF AMembers(laProp, m.toObj) > 0
FOR EACH lcProp IN laProp
IF NOT (.F.;
OR PemStatus(m.toObj, m.lcProp, 1); && read-only
OR PemStatus(m.toObj, m.lcProp, 2); && protected
)
IF Type('m.toObj.' + m.lcProp, 1) == 'A'
lnRow = Alen(m.toObj.&lcProp, 1)
lnCol = Alen(m.toObj.&lcProp, 2)
llResult = .T.;
AND AddProperty(;
m.loResult;
, m.lcProp + Textmerge(Iif(m.lnCol > 0,
'[<<m.lnRow>>, <<m.lnCol>>]', '[<<m.lnRow>>]'));
, Iif(Vartype(m.luProp) == 'O';
, oClone(m.luProp);
, m.luProp;
);
);
AND Acopy(m.toObj.&lcProp, m.loResult.&lcProp) > 0
ELSE
luProp = Evaluate('m.toObj.' + m.lcProp)
llResult = AddProperty(;
m.loResult;
, m.lcProp;
, Iif(Vartype(m.luProp) == 'O';
, oClone(m.luProp);
, m.luProp;
);
)
ENDIF
ASSERT m.llResult
ENDIF
ENDFOR
ENDIF
IF m.toObj.BaseClass = 'Collection' AND m.toObj.Count > 0
FOR liItem = 1 TO m.toObj.Count
lcKey = m.toObj.GetKey(m.liItem)
llResult = Iif(Empty(m.lcKey);
, m.loResult.add(m.toObj.Item(m.liItem));
, m.loResult.add(m.toObj.Item(m.liItem), m.lcKey);
)
ASSERT m.llResult
ENDFOR
ENDIF
ENDIF
RETURN m.loResult
Thierry Nivelet
FoxInCloud
Give your VFP app a second life in the cloud
http://foxincloud.com/
Le 26/06/14 01:37, mbsoftwaresoluti...@mbsoftwaresolutions.com a écrit :
(VFP9SP2)
I've got code that's something like this:
loRec = this.oRecord
do form MyForm name loFrm noshow
loFrm.oRecord = this.oRecord
loFrm.Show()
* user makes some changes to loFrm.oRecord, but user presses Cancel
button so I want to revert those changes
if loFrm.lSaved then
* do some requerying as data was saved via loFrm
else && and this is the scenario where I'm asking for tips
* the changes made in loFrm.oRecord have stayed changed in
this.oRecord. I want separation of the two so when the user reverts,
this.oRecord is NOT affected
endif
Ideas? I did something many years ago where I separated objects but
can't recall that voodoo at present.
Thanks,
--Mike
[excessive quoting removed by server]
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/53abd42c.1030...@foxincloud.com
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.