Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9317729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:56:55+00:00 2026-06-19T02:56:55+00:00

What is the difference between TFuncOfIntToString = reference to function(x: Integer): string; and TFuncOfIntToString

  • 0

What is the difference between

TFuncOfIntToString = reference to function(x: Integer): string; 

and

TFuncOfIntToString = function(x: Integer): string of object; 

I use the of object

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:56:56+00:00Added an answer on June 19, 2026 at 2:56 am

    Let us consider the following three type declarations:

    TProcedure = procedure;
    TMethod = procedure of object;
    TAnonMethod = reference to procedure;
    

    These are all very similar to each other. In terms of calling instances of each of these three types, the calling code is identical. The differences arise in what can be assigned to variables of these types.

    Procedural types

    TProcedure is a procedural type. You can assign to a variable of type TProcedure something of this form:

    procedure MyProcedure;
    begin
    end;
    

    This is a non object-oriented procedure. You cannot assign an instance or class method to a TProcedure variable. However, you can assign a static class method to a TProcedure variable.

    Method pointers

    TMethod is a method pointer. This is indicated by the presence of of object. When you have a variable of type TMethod you must assign either:

    1. A instance method of an instantiated object, or
    2. A class method.

    So you can assign either of these:

    procedure TMyClass.MyMethod;
    begin
    end;
    
    class procedure TMyClass.MyClassMethod;
    begin
    end;
    

    The big difference between a procedural type and a method pointer is that the latter contains a reference to both code and data. A method pointer is often known as a two-pointer procedural type. A variable that contains a method pointer contains references to the code and the instance/class to call it on.

    Consider the following code:

    var
      instance1, instance2: TMyClass;
      method1, method2: TMethod;
    ....
    method1 := instance1.MyMethod;
    method2 := instance2.MyMethod;
    

    Now, although method1 and method2 refer to the same piece of code, they are associated with different object instances. So, if we call

    method1();
    method2();
    

    We are invoking MyMethod on the two distinct instances. That code is equivalent to:

    instance1.MyMethod();
    instance2.MyMethod();
    

    Anonymous methods

    Finally we come to anonymous methods. These are even more general purpose than procedural types and method pointers. You can assign any of the following to a variable defined using the reference to syntax:

    1. A plain non object-oriented procedure.
    2. An instance method of an instantiated class.
    3. A class method.
    4. An anonymous method.

    For example:

    var
      AnonMethod: TAnonMethod;
    ....
    AnonMethod := MyProcedure;            // item 1 above
    AnonMethod := instance1.MyMethod;     // item 2
    AnonMethod := TMyClass.MyClassMethod; // item 3
    

    Anonymous methods, item 4 above, are those declared in-line in your code. For example:

    var
      AnonMethod: TAnonMethod;
    ....
    AnonMethod := procedure
      begin
        DoSomething;
      end;
    

    The biggest benefit of anonymous methods when compared to the procedural types and method pointers is that they allow for variable capture. For example consider the following short program to illustrate:

    {$APPTYPE CONSOLE}
    program VariableCapture;
    
    type
      TMyFunc = reference to function(X: Integer): Integer;
    
    function MakeFunc(Y: Integer): TMyFunc;
    begin
      Result := function(X: Integer): Integer
        begin
          Result := X*Y;
        end;
    end;
    
    var
      func1, func2: TMyFunc;
    
    begin
      func1 := MakeFunc(3);
      func2 := MakeFunc(-42);
      Writeln(func1(4));
      Writeln(func2(2));
      Readln;
    end.
    

    This has the following output:

    12
    -84
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

difference between hash code and reference or address of an object?
The difference between reference types and value types is often confusing for beginners due
What's the difference between: function bar() { for (x=0; x< 100; x++) {} }
//Difference between 2 dates This function works well but display wrong time format. Pls
Possible Duplicate: Difference between (function(){})(); and function(){}(); Are (function ( ) { } )
So...what is the difference between unicorn and unicorn_rails When should I use one or
Difference between value parameter and reference parameter ? This question is asked sometime by
Any difference between these two statements? $(document).ready(function() { // Code }); $(function() { //
What is the difference between setPropertyActionListener vs attribute vs param ? When would use
What is the difference between these two types of running a JavaScript function? (function()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.