RecordRef is a pointer!

Oh hai, it’s been a while. I’ve not been doing much coding in the last couple of years but now I’m right back into it, so here’s a short post to learn from my mistakes…

Say you have a function (OnGlobalModify for example) that gives you a RecRef, but no xRefRef and you want to compare what has changed.

DON’T DO THIS:
xRecRef := RecRef;
xRecRef.find();

Why? Because RecordRef is effectively a Pointer. And if you copy a pointer then both copies of the pointer still point at the same place. So the xRecRef.find() will effectively call Find on both and then when you compare them they will be the same (and you may have reverted all your changes, oops!)

INSTEAD DO THIS:
xRecRef.OPEN(RecRef.NUMBER);
xRecRef.GET(RecRef.RECORDID);

OR THIS:
Variant := RecRef;
xRecRef.GetTable(Variant);
xRecRef.find();

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s