Bueno he seguido investigando y me he encontrado con un problema.
supongamos esto :
Código Delphi
[-]
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, dxCntner, dxEditor, dxExEdtr, dxEdLib, Spin;
type
TForm1 = class(TForm)
cbFunciones: TComboBox;
btnAdd: TButton;
btnEjecutar: TButton;
spin: TSpinEdit;
ListBox1: TListBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure btnAddClick(Sender: TObject);
procedure btnEjecutarClick(Sender: TObject);
private
public
funciones : array of procedure of object;
metodos : array of array[0..3] of String;
procedure funcion1(nombre:String);
procedure funcion2(valor,nombre:String);
procedure funcion3;
procedure funcion4(nombre,valor,arg:String);
procedure funcion5;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnAddClick(Sender: TObject);
begin
if cbFunciones.Text <> '' then
begin
SetLength(metodos,spin.Value+1);
metodos[spin.Value][0] := cbFunciones.Text;
metodos[spin.Value][1] := edit1.Text;
metodos[spin.Value][2] := edit2.Text;
metodos[spin.Value][3] := edit3.Text;
spin.Value := spin.Value + 1;
btnEjecutar.Enabled := true;
listBox1.Items.Add(cbFunciones.Text);
end;
end;
procedure TForm1.btnEjecutarClick(Sender: TObject);
var
i : integer;
begin
cbFunciones.Enabled := false;
btnEjecutar.Enabled := false;
for i:= 0 to high(metodos) do
begin
SetLength(funciones,i+1);
if metodos[i][0] = 'funcion1' then
funciones[i] := funcion1(metodos[i][1]); if metodos[i][0] = 'funcion2' then
funciones[i] := funcion2(metodos[i][1],metodos[i][2]); if metodos[i][0] = 'funcion3' then
funciones[i] := funcion3;
if metodos[i][0] = 'funcion4' then
funciones[i] := funcion4(metodos[i][1],metodos[i][2],metodos[i][3]); if metodos[i][0] = 'funcion5' then
funciones[i] := funcion5;
end;
for i:= 0 to high(funciones) do
begin
funciones[i];
application.ProcessMessages;
spin.Value := spin.Value - 1;
if i <> high(funciones) then
sleep(6000);
end;
funciones := nil;
metodos := nil;
btnAdd.Enabled := true;
ListBox1.Clear;
cbFunciones.Enabled := true;
end;
procedure TForm1.funcion1(nombre:String);
begin
ShowMessage('Ejecutando la función 1:'+nombre);
end;
procedure TForm1.funcion2(valor,nombre:String);
begin
ShowMessage('Ejecutando la función 2'+valor+' '+nombre);
end;
procedure TForm1.funcion3;
begin
ShowMessage('Ejecutando la función 3');
end;
procedure TForm1.funcion4(nombre,valor,arg:String);
begin
ShowMessage('Ejecutando la función 4'+nombre+' '+valor+' '+arg);
end;
procedure TForm1.funcion5;
begin
ShowMessage('Ejecutando la función 5');
end;
end.
En todos los puntos donde le he pasado un argumento me da este error:
Incompatible types: 'Procedure of object' and 'procedure, untyped pointer or untyped parameter'