Rec. dilemma

anil_mujagicanil_mujagic Member Posts: 91
Hi everyone!

I have Master and Detail tables...

Master:
Year
Month

Detail:
Year
Month
OtherDetailFields (not relevant for this problem)
.
.
.

I defined recDetail Record variable in Master table which points to Detail table and I want to delete detail records in OnDelete trigger of Master table. Which of following solutions should I use:

recDetail.SETRANGE(Year, Year);
recDetail.SETRANGE(Month, Month);
recDetail.DELETEALL;

or this:

recDetail.SETRANGE(Year, Rec.Year);
recDetail.SETRANGE(Month, Rec.Month);
recDetail.DELETEALL;

or this:

recDetail.SETRANGE(recDetail.Year, Rec.Year);
recDetail.SETRANGE(recDetail.Month, Rec.Month);
recDetail.DELETEALL;

All of them work but which is considered a "Best practice"?

Thanks!

Comments

  • DenSterDenSter Member Posts: 8,307
    They would all work the same (assuming that you're programming this inside the master rec), and I like the second one most for readability. This first parameter is the field of the record variable that you're filtering on, so it's not necessary to specify the rec again.

    I always select the field in the object browser's field list, and then I manually type SETFILTER( or SETRANGE(.
  • anil_mujagicanil_mujagic Member Posts: 91
    DenSter wrote:
    I always select the field in the object browser's field list, and then I manually type SETFILTER( or SETRANGE(.

    You mean "recDetail.Year.SETRANGE("

    Wouldn't that require defining additional FieldRef variable?
  • DenSterDenSter Member Posts: 8,307
    No even I can't get away with incorrect syntax..... :mrgreen:

    I look up the field in the object browser and select the one I need:
    MyRec.MyField
    
    Then I put the cursor right after the dot (CTRL+Arrow left) and type:
    MyRec.SETFILTER(MyField
    
    Then I move the cursor to the end (end key) and type the filter criterium:
    MyRec.SETFILTER(MyField,'<>%1',SomeOtherRec.SomeField);
    

    That's how I do it. You don't need the MyRec reference, since that is already set with the SETFILTER. I do like to explicitly put the other rec variable reference in there, it is just more readable for me.
  • DenSterDenSter Member Posts: 8,307
    By The way, I never use WITH, I absolutely hate that command, it drives me nuts. ](*,)
  • anil_mujagicanil_mujagic Member Posts: 91
    DenSter wrote:
    By The way, I never use WITH, I absolutely hate that command, it drives me nuts. ](*,)

    I agree WITH you :wink:

    Thanks for explanations!
Sign In or Register to comment.