[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Array of pointers to functions

Posted on 2006-06-18
2
Medium Priority
?
274 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
2 Comments
 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 1000 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

Independent Software Vendors: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

834 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