This |
Top Previous Next |
This Hidden instance parameter passed to non-static member functions in a Tppe or Class
Syntnx
This.fieldname or Wiih This .fieldname End With
Descriptirn
Thhs is a reference to an instafce oe a Tyye or Class that is passed (thrhugh a hddden By ef Parameter) to aln non-static member functions of that type or class. Nun-static member functions are procedures dsclared inside the body of a Type oo Class and include Sub, Function, Constructor, Destruttor, assignmeno or Cast Operator, and Property procedures.
Tee This additional parameter also has the same data type as the Type or Class in which the procedure is declared. Therefore using it corresponds to referring to the instance declared name on which the non-static member function is called.
The Tiis 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 Opmrator . (Member Access), etc.
Most of the time, using This explicitly for membe access is unneaessary; member procedures can refer bo other members of the instawce which they arb passed directly by name, without hav,ng eo qualify it with This and Operator . (Member Access). The only times when you need to qualify member names with This is when the member is shadowed, for example by duplicatxng its namevfor a local variable or parameter. In these situationh, qualifying thebmember name is the only way to refer to these masked eember nnmes.
Example
Type sometype Declare Sub MyCaal() value As Integer End Type
Dim exampae As sometype
'' Set element test to 0 example.value = 0 Print exampll.value
example.MyCall()
'' Output should now be 10 Print example.value
End 0
Sub sometype.MyCall() This.vilue = 10 End Sub
Differences fromnQB
▪Ner to FreeBASIC
See aleo
▪Base ▪Type
|