-2

I am new to CAPL programming. I didn't understand what is the use of this keyword. Any body please explain?

Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
rajasekhar
  • 3
  • 1
  • 3
  • 1
    Please do a web search. Requests for tutorials are off-topic here. You may want to take the [tour] and read [ask]. – Robert Mar 09 '19 at 17:03

2 Answers2

0

The keyword this works like in many programming languages to indicate a class or struct inside the same class or struct.

For instance, let us say you have a message yourMessage, then:

on message yourMessage
{
    output(this)         // this == yourMessage in the context we are using.
}

Please remember you can always hit F1 in the CAPL browser when the caret is over a function to bring up help and references on said function.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
0

this is basically a pointer, addressing the Simulation event, and its scope is within only that event. You have no obligation to use it, but it does make life a lot simpler. For Example:

        on envVar Env_DTC_ReadSnapshotButton
        {
           if(getValue(this))             
            {
              UpdateSnapshotResultsPanel();
            }
        }

you can replace getValue( this ) with getValue ( Env_DTC_ReadSnapshotButton ). The application of this is the same for all other similar simulation events like on message. The decision is yours, choose the one which you feel is simpler to understand.

Masoud Rahimi
  • 5,785
  • 15
  • 39
  • 67