`this` keyword equivalent in delphi

Billydan

Let's say that we have this class:

unit Traitement;

interface

type
  TTraitement =class
  public        
    function func1(param:String): String;
    function func2(param:String): String;
  end;

implementation

function TTraitement.func1(param:String): String;
begin
  //some code
end;

function TTraitement.func2(param:String): String;
begin
  //some code
end;

end.

And I want to call func1 in the code of func2. Well I used to be a Java programmer, and in this case I would use the keyword this. Does Pascal have an equivalent for the this keyword? If not, how can I achieve this kind of call?

David Heffernan

The equivalent to Java's this in Delphi is Self. From the documentation:

Self

Within the implementation of a method, the identifier Self references the object in which the method is called. For example, here is the implementation of TCollection Add method in the Classes unit:

function TCollection.Add: TCollectionItem;
begin
  Result := FItemClass.Create(Self);
end;

The Add method calls the Create method in the class referenced by the FItemClass field, which is always a TCollectionItem descendant. TCollectionItem.Create takes a single parameter of type TCollection, so Add passes it the TCollection instance object where Add is called. This is illustrated in the following code:

 var MyCollection: TCollection;
 ...
 MyCollection.Add   // MyCollection is passed to the 
                    // TCollectionItem.Create method

Self is useful for a variety of reasons. For example, a member identifier declared in a class type might be redeclared in the block of one of the class' methods. In this case, you can access the original member identifier as Self.Identifier.

Note, however, that the example code in the question has no need to use Self. In that code you can call func1 from func2 omitting Self.

The example given in the above documentation excerpt does provide proper motivation for the existence of Self.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Equivalent of "in" keyword or subquery in pandas

From Dev

Lucene - equivalent of SQL "IN" keyword

From Dev

Delphi self keyword

From Dev

STL container equivalent of Delphi set?

From Dev

Is there a delphi ScrollInView equivalent in Free Pascal?

From Dev

What is the equivalent of SQL's IN keyword in R?

From Dev

C# equivalent to C++ friend keyword?

From Dev

Ruby Regexp using gsub is there an equivalent to self keyword?

From Dev

Is There A Java Equivalent To C# Out Keyword

From Dev

GLSL ES equivalent to OpenGL GLSL 'out' keyword?

From Dev

Is There A Java Equivalent To C# Out Keyword

From Dev

POINTER keyword in FORTRAN equivalent in C/C++

From Dev

GLSL ES equivalent to OpenGL GLSL 'out' keyword?

From Dev

Delphi "default" keyword with Record types in older Delphi versions

From Dev

Delphi "default" keyword with Record types in older Delphi versions

From Dev

Is there a Delphi's "with..do" Java equivalent?

From Dev

What is the Delphi equivalent to the C __builtin_clz()?

From Dev

Delphi equivalent to Free Pascal's FPC define?

From Dev

equivalent enumerable.max function in delphi

From Dev

What is the Delphi equivalent to C++'s memset?

From Dev

Equivalent of yield return of C# in delphi

From Dev

Is there a Delphi equivalent to Java interfaces ("class ... implements")?

From Dev

What is the Delphi equivalent of C# generic list

From Dev

Delphi equivalent to Free Pascal's FPC define?

From Dev

equivalent enumerable.max function in delphi

From Dev

Equivalent of yield return of C# in delphi

From Dev

what is SQL Server Money equivalent datatype in Delphi

From Dev

Is there any Equivalent Keyword in android like "with" in VB6

From Dev

What is the C# Equivalent of java's transient keyword?

Related Related

  1. 1

    Equivalent of "in" keyword or subquery in pandas

  2. 2

    Lucene - equivalent of SQL "IN" keyword

  3. 3

    Delphi self keyword

  4. 4

    STL container equivalent of Delphi set?

  5. 5

    Is there a delphi ScrollInView equivalent in Free Pascal?

  6. 6

    What is the equivalent of SQL's IN keyword in R?

  7. 7

    C# equivalent to C++ friend keyword?

  8. 8

    Ruby Regexp using gsub is there an equivalent to self keyword?

  9. 9

    Is There A Java Equivalent To C# Out Keyword

  10. 10

    GLSL ES equivalent to OpenGL GLSL 'out' keyword?

  11. 11

    Is There A Java Equivalent To C# Out Keyword

  12. 12

    POINTER keyword in FORTRAN equivalent in C/C++

  13. 13

    GLSL ES equivalent to OpenGL GLSL 'out' keyword?

  14. 14

    Delphi "default" keyword with Record types in older Delphi versions

  15. 15

    Delphi "default" keyword with Record types in older Delphi versions

  16. 16

    Is there a Delphi's "with..do" Java equivalent?

  17. 17

    What is the Delphi equivalent to the C __builtin_clz()?

  18. 18

    Delphi equivalent to Free Pascal's FPC define?

  19. 19

    equivalent enumerable.max function in delphi

  20. 20

    What is the Delphi equivalent to C++'s memset?

  21. 21

    Equivalent of yield return of C# in delphi

  22. 22

    Is there a Delphi equivalent to Java interfaces ("class ... implements")?

  23. 23

    What is the Delphi equivalent of C# generic list

  24. 24

    Delphi equivalent to Free Pascal's FPC define?

  25. 25

    equivalent enumerable.max function in delphi

  26. 26

    Equivalent of yield return of C# in delphi

  27. 27

    what is SQL Server Money equivalent datatype in Delphi

  28. 28

    Is there any Equivalent Keyword in android like "with" in VB6

  29. 29

    What is the C# Equivalent of java's transient keyword?

HotTag

Archive