Recent

Author Topic: Signal on button press  (Read 1132 times)

yyttyy

  • New Member
  • *
  • Posts: 18
Signal on button press
« on: December 08, 2020, 06:24:02 am »
What's wrong?

2 signals:

Code: Pascal  [Select][+][-]
  1. function button_pressed(button : PGtkWidget; event: PGdkEvent;
  2.                         data : gpointer) : boolean; cdecl;
  3. begin
  4.     if (event^._type = GDK_BUTTON_PRESS) then
  5.         writeln('Кнопка нажата');
  6.     button_pressed := true;
  7. end;
  8.  
  9. function button_released(button : PGtkWidget; event : PGdkEvent;
  10.                          data : gpointer) : boolean; cdecl;
  11. begin
  12.     if (event^._type = GDK_BUTTON_RELEASE) then
  13.         writeln('Кнопка отжата');
  14.     button_released := true;
  15. end;

Connecting with the signals and maping:

Code: Pascal  [Select][+][-]
  1. ...
  2. button := gtk_button_new_with_label('1');
  3.     gtk_widget_add_events (button, GDK_BUTTON_PRESS_MASK
  4.                            or GDK_BUTTON_RELEASE_MASK);
  5.     buttonbox := gtk_fixed_new();
  6.     g_signal_connect(G_OBJECT(button), 'clicked',
  7.                      G_CALLBACK(@button_pressed), nil);
  8.     g_signal_connect(G_OBJECT(button), 'released',
  9.                      G_CALLBACK(@button_released), nil);
  10.     gtk_widget_set_size_request(button, 50, 30);
  11.     gtk_fixed_put(GTK_FIXED(buttonbox), button, 100, 100);
  12.     gtk_widget_show(button);
  13.     gtk_container_set_border_width(GTK_CONTAINER(Window), 0);
  14.     gtk_container_add(GTK_CONTAINER(Window), buttonbox);
  15.     gtk_widget_show(buttonbox);
  16. ...

Error in terminal:

An unhandled exception occurred at $000000000040998D:
EAccessViolation: Access violation
  $000000000040998D

 

TinyPortal © 2005-2018