It is some time I have noticed one small change which is not described or I never see it in some official documentation (excluding help files). You know the drill when you need to pass temporary table:
You pass it as parameter by reference, or you copy the records one by one.
Sometime you will use the first, sometime you will use the second. Now, you have new possibility:
You are thinking: “Oh, wait, it is not copying the data inside, only filters etc.!”
It is not true anymore. If you look into the Symbol menu to this function over some record variable, you will notice that there is new second parameter with name “ShareTable”. And this is it. If you set this parameter to “True” and you will call this COPY on some temporary table, the record variable to which you are copying will share the temporary table with the first variable! It means you see same data, but you have another variable to iterate and modify them!
TempVar1.Code := ‘TEST’;
TempVar1 and TempVar2 are temporary records e.g. over table 3. EASY! If you forgot to set the temporary on one of the variables, you will get this error in run time:
The COPY function can only be used with the shareTable argument set to true if both records are temporary.
Quote from the on-line help:
Specifies whether the function creates a copy of the record or creates a reference to a temporary record.
If FromRecord and Record are both temporary and ShareTable is true, then the COPY function does not create a new copy of the record. Instead, the COPY function causes Record to reference the same table as FromRecord.
The default value is false. If you specify false, all records are copied to Record from FromRecord.
As you can see, there is one mistake in the description: if the parameter is false, regarding the online help it should copy the records. But THIS IS NOT TRUE! In this case, the same example with false parameter will give you same result (only the table will be another copy, not the same one), but the real result is error, because the table in TempVar2 is empty!
I think that many of you didn’t notice this change, which could help us to create much better code. Sometime even the standard objects are using arrays of record variables to solve this. Now, you can use different variables and set them to same instance of the temporary table by just using COPY on them.
Those little things makes me happy each time I find something like that.