Forum > Graphics

Fpc and gtk2 widget


I'm working width fpc and gtk2.
I have write an objet that create a gtk2 widget with a gtk2 button inside. Something like this:

--- Code: ---procedure TCamera.Init(CTitle: String; Cid_camera: Integer);
  vbox, frame, topbox: PGtkWidget;
  Camera:= Self;
  Frames:= 0;
  Title:= CTitle;
  id_camera:= Cid_camera;
  FWidth:= 800;
  FHeight:= 600;
  TThCameraClient:= nil;

  FWindow:= gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW (FWindow), PChar(Title));
  gtk_window_set_resizable(GTK_WINDOW(FWindow), FALSE);

  topbox:= gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(FWindow), topbox);
  frame:= gtk_frame_new(nil);
  gtk_box_pack_start(GTK_BOX(topbox), frame, FALSE, TRUE, 0);
  gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
  drawingarea:= gtk_drawing_area_new();
  gtk_drawing_area_size(GTK_DRAWING_AREA(drawingarea), FWidth, FHeight);
  gtk_container_add(GTK_CONTAINER(frame), drawingarea);

  vbox:= gtk_hbox_new(FALSE, 5);

  bplay:= gtk_button_new_with_label('Play');
  g_signal_connect(PGtkObject(bplay), 'clicked', GTK_SIGNAL_FUNC(@Play), Self);
  gtk_box_pack_start(GTK_BOX(vbox), bplay, FALSE, FALSE, 0);

--- End code ---

Look at this line:

g_signal_connect(PGtkObject(bplay), 'clicked', GTK_SIGNAL_FUNC(@Play), Self);

Every TCamera object creates a own gtk2 widget. Every gtk2 widget has a gtk2 button inside.
The OnClick event on the gtk2 button must grab from @Play function (owner by TCamera object).
If I create more TCamera object the OnClick function is grab on from the last object created. The others TCamera objects are not connected with their gtk2 widget.
How can I grab correctly the OnClick event from the corrected object?


[0] Message Index

Go to full version