Solved

Array of pointers to functions

Posted on 2006-06-18
2
271 Views
Last Modified: 2010-04-05
Let`s say I have these functions:

function A(v1, v2: Integer): boolean;
function B(v1: Integer): boolean;
function C: boolean;

I want an array like this:
Functions: Array[1..3] of pointer_to_functions;
then I want to point the array to those function and give me an example how to call the functions from the array.

Should be simple.

Thanks
0
Comment
Question by:crystyan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 250 total points
ID: 16929560
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  procedure Event1(Sender:tobject);
  procedure Event2(Sender:Tobject);
  procedure Event3(Sender:Tobject);
  function A(v1, v2: Integer): boolean;
  function B(v1: Integer): boolean;
  function C: boolean;

  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.Event1(Sender:Tobject);
begin
   A(10,100);
   showmessage('Event1 Activated');
end;

procedure TForm1.Event2(Sender:Tobject);
begin
  B(1000);
  showmessage('Event2 Activated');
end;

procedure TForm1.Event3(Sender:Tobject);
begin
  C;
  showmessage('Event3 Activated');
end;




function TForm1.A(v1, v2: Integer): boolean;
begin
  Result:=v1<v2;
end;


function TForm1.B(v1: Integer): boolean;
begin
  Result:=v1<100;
end;

function tform1.C: boolean;
begin
  Result:=False;
end;


var Functions: Array[1..3] of  TNotifyEvent;

procedure TForm1.Button1Click(Sender: TObject);
begin
  case strtoint(InputBox('Which event you want to point to For Button2Click Event','Which event you want to point to For Button2Click Event :(1/2/3)','1')) of
      1: button2.OnClick:=functions[1];
      2: button2.OnClick:=functions[2];
      3: button2.OnClick:=functions[3];
     else
      showmessage('Error!, out of Range(1 or 2 or 3)');
   end;


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Functions[1]:=Event1;
  Functions[2]:=Event2;
  Functions[3]:=Event3;
end;

end.


//////////////////////////////////
DFM
//////////////////////////////////

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 80
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 257
    Top = 29
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 1
  end
end
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 16934308
hmm,
not the solution i had guessed . . .
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question