Thread View: comp.lang.pascal.delphi.components.misc
3 messages
3 total messages
Started by btm
Tue, 14 Sep 1999 00:00
Function pointer problem
Author: btm
Date: Tue, 14 Sep 1999 00:00
Date: Tue, 14 Sep 1999 00:00
52 lines
2074 bytes
2074 bytes
In a general form used by several other forms I defined a function
reference like this [Delphi 1]:
type
TCheckFunc = function (FldNr: integer): Boolean;
TSetParam = class(TForm)
....
public
CheckStatus: TCheckFunc;
end;
In several of my forms I now want to do something like this:
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
function Form1Check (FldNr: integer): Boolean;
end;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var frm: TSetParam;
begin
frm:=TSetParam.create(self);
frm.CheckStatus:=Form1Check; { doesn't work! WHY? }
frm.showmodal;
frm.Release;
end;
function TForm1.Form1Check (FldNr: integer): Boolean;
begin
{ set to True or False according to specific conditions : }
result:=True;
end;
Alas, there is something wrong with this... The compiler says that the
assignment
frm.CheckStatus:=MyCheck;
is an invalid function/procedure reference. What's wrong with this?
Thanks for any hints!
Thomas
Re: Function pointer problem
Author: Liz Kimber
Date: Tue, 14 Sep 1999 00:00
Date: Tue, 14 Sep 1999 00:00
20 lines
1434 bytes
1434 bytes
> type
> TCheckFunc = function (FldNr: integer): Boolean;
> TSetParam = class(TForm)
> ....
> public
> CheckStatus: TCheckFunc;
> end;
You have declaed the CheckStatus to need something returning a type of
TCheckFunc..
You actually should have set it as boolean according to the procuedure
you made here
>
> function TForm1.Form1Check (FldNr: integer): Boolean;
> begin
> { set to True or False according to specific conditions : }
> result:=True;
> end;
Re: Function pointer problem
Author: Bruce Roberts
Date: Tue, 14 Sep 1999 00:00
Date: Tue, 14 Sep 1999 00:00
48 lines
2108 bytes
2108 bytes
btm <btm@gmx.net> wrote in message
news:37de2a8b.335943@news.spectraweb.ch...
> In a general form used by several other forms I defined a function
> reference like this [Delphi 1]:
>
> type
> TCheckFunc = function (FldNr: integer): Boolean;
This declares a function type that is declared at the main level of a unit,
not a class method.
> TSetParam = class(TForm)
> ....
> public
> CheckStatus: TCheckFunc;
> end;
>
> In several of my forms I now want to do something like this:
>
> type
> TForm1 = class(TForm)
> Button1: TButton;
> procedure Button1Click(Sender: TObject);
> private
> public
> function Form1Check (FldNr: integer): Boolean;
This is a class function.
> end;
>
You can either change your type definition to
TCheckFunc = function (FldNr: integer): Boolean of object;
or remove Form1Check from the form declaration and place it in the main body
of the unit, e.g.
type
form1 = . . .
end;
function Form1Check . . .
Either will correct the error. However in this case you probably want to
change the function type definition (the first suggestion).
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads