Accessing struct instance property from within function block instance

turndapage
2022-11-23
2022-11-23
  • turndapage - 2022-11-23

    Hi all,
    I've got a structure set up in this way:

    I have a STRUCT called "Cartridge" that has values.
    I have a FB called "Gripper"
    The gripper has a property called "CurrentCartridge" that holds and instance of Cartridge.

    In the program, I want to access the status of the current cartridge.
    If I type this statement:

    IF Gripper1.CurrentCartridge.Status = CartridgeStatus.Inspected THEN
        Robot.PlaceWeld(1);
    END_IF
    

    I get the error:
    It is not possible to perform component access '.', index access '[]' or call '()' on result of function call. Assign result to help variable first.

    However, if I assign this to a variable, it works:

    G1Cartridge := Gripper1.CurrentCartridge;
    IF G1Cartridge.Status = CartridgeStatus.Inspected THEN
        Robot.PlaceWeld(1);
    END_IF
    

    Is there a proper way to do it the first way? this seems really annoying.
    Thank you!

     
  • tvm - 2022-11-23

    You can maybe get around this by using a REFERENCE TO in your property. So your property could look like this:

    PROPERTY PUBLIC CurrentCartridge : REFERENCE TO CARTRIDGE
    CurrentCartridge REF= AllCartridges[currentcartridgeindex]; (*or whatever your backing variable is called*)
    

    The same works with arrays. Of course, this only works if you have a backing variable to refer to, if you're creating it on the fly, you'll have to use helper variables.

     
    • turndapage - 2022-11-23

      Awesome! That's exactly what I was looking for Thank you!

       
    • turndapage - 2022-11-23

      Awesome! That's exactly what I was looking for Thank you!

       

Log in to post a comment.