Problem with the WITH DO clause

TheKooriTheKoori Member Posts: 3
Hi

I had a strange problem today, with some previously working code, that wasn't made by me.

Without changing anything, some code just stopped working after i compiled the codeunit container it.

I have simplified the code, just to give you an idea, of what i was up against.

GlobalLotNo is a global variable, LotNo is a parameter in the function AssignLot, and the record Parameter "Order", contains a field called LotNo.

Previously, the GlobalLotNo would be assigned the value of LotNo (in this case '0001'). But now NAV uses the Order.LotNo instead, which in this case is blank.

The debugger doesn't know this, because it keeps displaying '0001' in LotNo (it thinks it is the parameter, and not the field.) (Yes, the debugger is not that clever, I know :o )

I can see why this is bad code, and you should not have a parameter called exactly the same as a field within a WITH DO clause.

But did the interpretation of this code change in some version of the NAV client ?


Please don't mind the code as much, because it is very simplified, I know this does absolutely nothing meaningful :)

OnRun()
AssignLot(OrderPending,'0001');

AssignLot(Order : Record "Order Request Pending";LotNo : Code[20])
WITH Order DO BEGIN
GlobalLotNo := LotNo;
END;

Best Regards
Thomas Korsgaard

Comments

  • kinekine Member Posts: 12,562
    I think that it was changed, but I do not know in which version. I just know that I already met this...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    That's another good reason why I always say Fields have to be named like "Lot No." and Variables have to be named like LotNo. When you set the cursor on the name in code you'll get a hint in the status bar what it is that you are focussing. (There are some limitation to this but in most of the cases it's enough.)
    "Money is likewise the greatest chance and the greatest scourge of mankind."
Sign In or Register to comment.