Bug avec OB copier

Bonjour,

j’ai la fâcheuse habitude d’écrire:

$ob:=OB copier($1)
au lieu de
$ob:=$1

Une habitude de vieux gars qui ne mange pas de pain.

He bien je viens de constater que $ob:=OB copier($1) ne copie pas les collections de $1, la fonction identifie les collections, leur longueur, mais elles sont vides.

J’ai découvert ça en utilisant la fonction MAIL Creer piece jointe qui utilise une collection pour les pièces jointes.

Bon, je vais donc désormais utilser $ob:=$1, mais cela n’empêche pas la bug.

Salut Eric,

Quelle n° de build utilises-tu pour la v18 ?
Je crois avoir vu passer un bug corrigé dans une NB récente.

Je vois ça : « MAIL Creer piece jointe retourne un nouvel objet pièce jointe […]. L’objet contient les propriétés et méthodes en lecture seule suivantes […] »
et je me demande si ton problème de copie n’est pas lié à ce lecture seule (et si par hasard c’est ça je suis bien incapable de l’interpréter).

Ceci dit, copier l’objet de départ, c’est juste plus de mémoire occupée pour re décrire le même objet, ça doit manger du pain. Je m’en sers quand je veux altérer la copie obtenue sans toucher l’original.

oui excusez-moi j’ai oublié la version.

17r4 build 235715 64bits

Bonjour Eric,

sans rentrer dans les détails, j’ai eu il y a quelques temps un soucis similaire et ce que j’ai appris, c’est que l’objet retourné par les commandes MAIL ne sont pas de “simples” objets tels qu’on a l’habitude de les manipuler en tant que tel.
Je pense que l’on te répondra que c’est du “standard behavior” :wink:

Patrick

Bonjour,

Attention type OBJECT and COLLECTION are different types!

  • OB Copy is only for OBJECTs
  • col.copy() is only for COLLECTIONs

https://doc.4d.com/4Dv17/4D/17.4/collectioncopy.305-4883361.fr.html

Test with Mac “4Dv18.249095” all is OK!
Test with Mac “4Dv17R5.239769” all is OK!
Test with Mac “4Dv17R4.234985” failed, col.copy is unknown ???

col.copy was created by 4Dv16R6 (a long time before “4Dv17R4.234985”)

<code 4D>
// Test with Mac “4Dv18.249095” all is OK!
// Test with Mac “4Dv17R5.239769” all is OK!
// Test with Mac “4Dv17R4.234985” failed, col.copy is unknown ???
// col.copy was created by 4Dv16R6 (a long time before “4Dv17R4.234985”)
// Attention type OBJECT and COLLECTION is not the same!
// - OB Copy is only for OBJECTs
// - col.copy() is only for COLLECTIONs
// Only to copy gives a autom object or collection
// This is sometimes important to copy obj/col first from $1 to $localVar
// when never the orgObj/orgCol is wished to change inside the called method!
// Go save way first copy $1 (obj/col) inside method and then use the copy
// when your method must be neutral and not changing anything on original.
// CallParams from type pointer/object/collection make it possible to
// make changes on originals (when this not wished make it save and copy it first).

// ---- OBJECT ----
C_OBJECT($objOrgVar1;$objOrgVar2;$objCopyFromOrg)

$objOrgVar1:=New object(“a”;True;“x”;False)
$objOrgVar2:=$objOrgVar1
$objCopyFromOrg:=OB Copy($objOrgVar1)

$objOrgVar1:=New object(“a”;New collection(0;1;2);“x”;New collection(0;1;2))
$objOrgVar2:=$objOrgVar1
$objCopyFromOrg:=OB Copy($objOrgVar1)

// ---- COLLECTION ----
C_COLLECTION($colOrgVar1;$colOrgVar2;$colCopyFromOrg)

$colOrgVar1:=New collection(0;1;2)
$colOrgVar2:=$colOrgVar1
$colCopyFromOrg:=$colOrgVar1.copy()

$colOrgVar1:=New collection(New object(“a”;True;“x”;False);New object(“b”;False;“x”;True))
$colOrgVar2:=$colOrgVar1
$colCopyFromOrg:=$colOrgVar1.copy()

// Var1 and Var2 references to same one original
// When original changed with var1, you change the original,
// and both Var1 and Var2 represent same new changed original.
$colOrgVar2.push(New object(“new”;False;“x”;False))
// Now $colOrgVar1 and $colOrgVar2 shows this new added entry, because both ref to same org
// (( This did not happen with a COPY, when it is not wished ))
</code 4D>

Sorry i did not know which mail-functions you mean, so i can not know which kind of object you got from it. A Link to 4Ddoku site is international in all languages available, than i can verify which kind of object you mean.

: Lutz VEITH

Bonjour,
Attention type OBJECT and COLLECTION are different types!
Hi Lutz,
true, and interesting…
But I think you missed that, in Eric’s problem, the doc says MAIL New attachment returns a new attachment object. If this object embeds a collection, it’s supposed to be in the clone as well, no? As Patrick said, it may be “standard behaviour” because we don’t see the whole object (as a write pro object in the debugger: I don’t see the document content).

Sorry i only forgot in v17r4 to activate dot-notation :wink:

Test with Mac “4Dv18.249095” all is OK!
Test with Mac “4Dv17R5.239769” all is OK!
Test with Mac “4Dv17R4.234985” all is OK with col.copy() and with OB copy()

: Arnaud DE MONTARD

MAIL New attachment

Thank you Arnaud, now i found the command and resultObj.

Yes only the read-only special-objects(object MAIL Attachment)
in mail.attachments collection items can not be copy!

But it can represented with other vars/parameters($1):
$obj:=$mail
or with
$col:=$mail.attachments

Tested with 4Dv17r4, v17r5 and v18

<code 4D>
C_BLOB($blob)
SET BLOB SIZE($blob;0)
C_TEXT($txt)
$txt:=“Any 4D test text”
VARIABLE TO BLOB($txt;$blob)

C_OBJECT($email)
$email:=New object
$email.from:="user@mail.com"
$email.to:="customer@mail.com"
$email.subject:=“New annual report”
$email.textBody:=“Please find enclosed our latest annual report.”
$email.attachments:=New collection(MAIL New attachment($blob;“4dtxt.dta”))

C_OBJECT($obj)
$obj:=OB Copy($email)
// Only the read-only “object MAIL Attachment” in colAttachments can not copy
// the result: colAttachments contains empty objects instead

$obj:=$email
// Successfully, now $obj and $email reference to same orginal-object
// and the objects in colAttachments fully represented by both vars.
// This works too with C_OBJECT($1) succesfully whith myMethod1($email) and $obj:=$1 inside

C_COLLECTION($col)
$col:=$email.attachments.copy()
// The read-only “object MAIL Attachment” in colAttachments can not copy
// the result: colAttachments contains empty objects instead

$col:=$email.attachments
// Successfully, now $col and $email.attachments reference to same orginal-collection
// and the objects in colAttachments fully represented by both vars.
// This works too with C_COLLECTION($1) succesfully whith myMethod2($email.attachments) and $col:=$1 inside
</code 4D>

Yes Arnaud,
i understand what you mean with “WritePro Documents” example
and this is a little bit correct.

The difference is that “WritePro Documents” can fully copied
with Command “OB Copy”.
Fully means, not only the visible parts from debugger.
With “OB Copy” you create a complete copy of a whole wrpDocument,
including too the document contents.
To get access to the wp-contents you need the wp-commands.

In general, a copy not only protects against inadvertently unintentionally changing a work object (if not intended / intended),
but can also bring huge advantages in terms of speed. This always applies if a change to the original is not intended / desired.

This one i did in every method,
where i did not want to change the original wrpDoc.

C_OBJECT($wrpDoc;$1)
$wrpDoc:=OB Copy($1)

For example, stay in a form with displayed original wrpDoc
and than i only want to call a analyzeWrpDocMethod
which only returns me all analyze results in a separat jsonObj.
This method “analyzeWrpDocMethod”
fired >10100 operations against the wrpDoc.
On displayed original wrpDoc this need more than 8000ms
on copy(not displayed) of wrpDoc this need less then 80ms
to get all my analyze results.

Sometimes when very huge operations+changes must done
in the original(displayed) wrpDoc,
i did the same.

// PM: “getUpatedWrpDoc”
C_OBJECT($0)
C_OBJECT($wrpDoc;$1)
$wrpDoc:=OB Copy($1)
upateWrpDoc($wrpDoc)
$0:=$wrpDoc

MethodCalling like this:
wrpDocOrg:=getUpatedWrpDoc(wrpDocOrg)

This is only required when huge operations must done
and if the original is currently displayed.

If that’s not the case then i can change the original directly
with a other method “upateWrpDoc”:
// Method “upateWrpDoc” change original directly
// and create no speed-opt copy of maybe displayed original wrpDoc.
upateWrpDoc(wrpDocOrg)