Home AMX User Forum NetLinx Studio

get_last

adysadys Posts: 395
Is its safe to call get last from a function that called from the EVENT and not inside the Event code itself?


I mean if I have button event, and in the button event I call to function doX that call to function doY. inside doY i need the Tp that cause the event, so I call get_last with my global TP_LIST.

That works ok, I just wonder if that is safe and if what will happend if some event will enter in multiy TP enviroment.

thanks

Ady.

Comments

  • GSLogicGSLogic Posts: 562
    Pass the TP number to the function, this way you can have multiple panels using the function.
    DEFINE_FUNCTION whatEver(integer nPNL)
    {
      //nPNL is your get_last panel number
    }
    
    //#############################################
    BUTTON_EVENT[dTP,btArray]
    {
      PUSH:
      {
         whatEver(get_last(dTP));
      }
    }
    
  • adysadys Posts: 395
    That what I am trying to avoid :)

    I have lots of written code that need to be changed - or to pass the TP or just to call get_last.

    The question is if it safe, if there is a kind of build in protection on it
  • GSLogicGSLogic Posts: 562
    I'm not really sure what you are asking but, you should have all events/functions look to the TP that triggered the event. If you are working in a large system with many TPs this is a MUST! It is good practice to store feedback in a structure and only send feedback to TPs that need to be updated.
  • adysadys Posts: 395
    I am just asking if its safe to ask get_last after some time that the event happend?

    Or maybe I can get the new event data (event that I am still on the flow of the first event)?

    An example:


    BUTTON_EVENT
    .....

    get_last.
    ..
    ...

    call Function X
    call Function Y
    ..


    Function Y Body

    {
    get_last

    }


    There is a chance that in the time between the button event and the get_last call inside function Y a new event will trigger.

    The question is, what get_last will return? the new event TP of the current event TP?
  • DHawthorneDHawthorne Posts: 4,584
    No, it's not safe. The value could have changed. In many cases, it's not likely, but it is possible. The best practice is to keep get_last inside the event handler, and pass the return value to your function.
  • adysadys Posts: 395
    DHawthorne wrote:
    No, it's not safe. The value could have changed. In many cases, it's not likely, but it is possible. The best practice is to keep get_last inside the event handler, and pass the return value to your function.

    Thanks, that what I wanted to know.
  • viningvining Posts: 4,368
    DHawthorne wrote:
    The best practice is to keep get_last inside the event handler, and pass the return value to your function.

    Isn't that in a sense what the code snippet that GSLogic provided below does. The get_last function w/in the whatever function occurs in the Button_Event and its returned value is passed to the function whatever.

    Code:
    DEFINE_FUNCTION whatEver(integer nPNL)
    {
      //nPNL is your get_last panel number
    }
    
    //#############################################
    BUTTON_EVENT[dTP,btArray]
    {
      PUSH:
      {
         whatEver(get_last(dTP));
      }
    }__________________
    
Sign In or Register to comment.