[fpc-pascal]About "callbacks method" of a class
mili
milimeter at 163.com
Wed Nov 13 15:37:55 CET 2002
Hello, everybody
I am using gtk2forpascal. I want to program as follows:
>>>>>
TButton = class(Tobject)
private
FButton:PGtkWidget;
public
constructor Create;
destructor Destroy;
procedure Callback_OnClick(widget:PGtkWidget; data:Object); cdecl;
end;//TButton
constructor TButton.Create;
begin
inherited Create;
FButton:=gtk_button_new_with_label('Click Me!');
gtk_widget_show(FButton);
g_signal_connect(G_OBJECT(FButton),'clicked',
TGCALLBACK(@Callback_OnClick),self);
...
end;//TButton.Create
procedure TButton.Callback_OnClick(widget:PGtkWidget; data:Object); cdecl;
begin
......
end;//TButton.Callback_OnClick
<<<<<
But I can't comiler this program. When I connect the signal with a subroutine
which is not a method, the compilation works. Can anybody confirm me that: In
class definition, We can't use "@MethodName" and in one method there's no way
to directly connect a signal with another method in the same class? In short,
is there "callbacks method"?
And another problem, I found the following code style in Lazarus project
sources:
>>>>>
procedure TSomeClass.FuncName(...);
procedure FuncNameEmbeded(...);
begin
.....
end;//FuncNameEmbeded
begin
end;//TSomeClass.FuncName
<<<<<
I know it's "nested procedure". But the information from fpc documentations is
too little. can you tell me more about it? Why the following code can compile
but will run with "Access violation"?
>>>>>
procedure TSomeClass.FuncName(...);
procedure FuncNameEmbeded(...);
begin
.....
writeln(FValue);//Here FValue is a member (Integer) of TSomecalss
.....
end;//FuncNameEmbeded
begin
end;//TSomeClass.FuncName
<<<<<
Thanks,
Yours,
mili
More information about the fpc-pascal
mailing list