About Procedural Types

F: TIntegerFunction; integer }

{ F is a parameterless function that returns an

Proc: TProcedure; SP: TStrProc; M: TMathFunc;

{ Proc is a parameterless procedure } { SP is a procedure that takes a string parameter } { M is a function that takes a Double (real)

type

TMethod = procedure of object;

TNotifyEvent = procedure(Sender: TObject) of object;

These types represent method pointers. A method pointer is really a pair of pointers; the first stores the address of a method, and the second stores a reference to the object the method belongs to. Given the declarations type

TNotifyEvent = procedure(Sender: TObject) of object; TMainForm = class(TForm)

procedure ButtonClick(Sender: TObject);

end; var

MainForm: TMainForm; OnClick: TNotifyEvent we could make the following assignment.

OnClick := MainForm.ButtonClick;

Two procedural types are compatible if they have

  • the same calling convention,
  • the same return value (or no return value), and
  • the same number of parameters, with identically typed parameters in corresponding positions. (Parameter names do not matter.)

Procedure pointer types are always incompatible with method pointer types. The value nil can be assigned to any procedural type.

Nested procedures and functions (routines declared within other routines) cannot be used as procedural values, nor can predefined procedures and functions. If you want to use a predefined routine like Length as a procedural value, write a wrapper for it:

function FLength(S: string): Integer; begin

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment