Recent

Author Topic: Fpc and gtk2 widget  (Read 5202 times)

mrdebug

  • Full Member
  • ***
  • Posts: 160
Fpc and gtk2 widget
« on: May 24, 2010, 05:50:47 pm »
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: [Select]
procedure TCamera.Init(CTitle: String; Cid_camera: Integer);
var
  vbox, frame, topbox: PGtkWidget;
begin
  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);

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?

 

TinyPortal © 2005-2018