AX 2012: this vs element | When to Use What?

In X++ we often come across an issue that we are unable to access an object member (e.g. a form method) via this keyword. Instead we CAN access the same form method via element keyword. So what’s the difference between them?

 

UntitledThe difference is of the scope. To understand how it works, let’s assume that we are standing at a button’s click method on a form and we need to access a method defined at the form level (e.g. readResourceFile() in this case). In this situation this keyword cannot access the method since its scope is only limited to the members of the current object. For example with this keyword we can access all the members of the button object. However, we can access the form-level method using the element keyword.

So element keyword has a bigger scope as compared to this keyword.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s