This
 
Hidden instance parameter passed to non-static member functions in a Type or Class

Syntax

This.fieldname
or
With This
.fieldname
End With

Description

This is a reference to an instance of a Type or Class that is passed as a hidden argument to all non-static member functions of that type or class. Non-static member functions are procedures declared inside the body of a Type or Class and include Sub, Function, Constructor, Destructor, assignment or cast Operator, and Property procedures.

The This additional parameter has the same data type as the Type or Class in which the procedure is declared.

The This parameter can be used just like any other variable, ie., pass it to procedures taking an object of the same type, call other member procedures and access member data using Operator . (Member Access), etc.

Most of the time, using This explicitly for member access is unnecessary; member procedures can refer to other members of the instance which they are passed directly by name, without having to qualify it with This and Operator . (Member Access). The only times when you need to qualify member names with This is when the member name is hidden, for example, by a local variable or parameter. In these situations, qualifying the member name is the only way to refer to these hidden member names.

Example

Type sometype
    Declare Sub MyCall()
    value As Integer
End Type

Dim example As sometype

'' Set element test to 0
example.value = 0
Print example.value

example.MyCall()

'' Output should now be 10
Print example.value

End 0

Sub sometype.MyCall()
    This.value = 10
End Sub


Differences from QB

  • New to FreeBASIC

See also