objreturn.pp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. { demo showing the choices when to return object. Note this program,
  2. * strictly speaking, is illegal in the usage of user data parameter
  3. * in the callback function.
  4. }
  5. program objreturn;
  6. uses xforms;
  7. {*** Forms and Objects ***}
  8. type
  9. TFD_FORM = record
  10. form0 : PFL_FORM;
  11. obj : array [0..3] of PFL_OBJECT;
  12. br : PFL_OBJECT;
  13. when : PFL_OBJECT;
  14. vdata : pointer;
  15. ldata : longint;
  16. end;
  17. PFD_FORM = ^TFD_FORM;
  18. var
  19. fd_form0 : PFD_form;
  20. { callbacks for form form0 }
  21. procedure return_cb(ob : PFL_OBJECT; data : longint); cdecl;
  22. begin
  23. fl_addto_browser(fd_form0^.br, pchar(data));
  24. end;
  25. procedure set_when( n : longint);
  26. begin
  27. fl_set_object_return(fd_form0^.obj[0], n);
  28. fl_set_object_return(fd_form0^.obj[1], n);
  29. fl_set_object_return(fd_form0^.obj[2], n);
  30. fl_set_object_return(fd_form0^.obj[3], n);
  31. end;
  32. procedure when_cb(ob : PFL_OBJECT; data : longint); cdecl;
  33. var n : longint;
  34. begin
  35. n := fl_get_choice(ob) - 1;
  36. if (n >= 0) then
  37. set_when(n);
  38. end;
  39. procedure resetlog_cb(ob : PFL_OBJECT; data : longint);cdecl;
  40. begin
  41. fl_clear_browser(fd_form0^.br);
  42. end;
  43. Function create_form_form0 : PFD_FORM;
  44. Const Preturn : pchar = 'slider returned';
  45. Pcounter : pchar = 'counter returned';
  46. Pinput : pchar = 'input2 returned';
  47. Pinput1 : Pchar = 'input1 returned';
  48. var
  49. obj : PFL_OBJECT;
  50. fdui : PFD_form;
  51. old_bw : longint;
  52. begin
  53. new(fdui);
  54. old_bw := fl_get_border_width();
  55. fl_set_border_width(-2);
  56. fdui^.form0 := fl_bgn_form(FL_NO_BOX, 321, 276);
  57. obj := fl_add_box(FL_UP_BOX,0,0,321,276,'');
  58. obj := fl_add_valslider(FL_HOR_SLIDER,12,55,138,22,'');
  59. fdui^.obj[0] := obj;
  60. fl_set_object_lalign(obj,FL_ALIGN_BOTTOM or FL_ALIGN_INSIDE);
  61. fl_set_object_callback(obj,PFL_CALLBACKPTR(@return_cb),longint(Preturn));
  62. fl_set_slider_return(obj, FL_RETURN_CHANGED);
  63. obj := fl_add_counter(FL_NORMAL_COUNTER,12,85,138,22,'');
  64. fdui^.obj[1] := obj;
  65. fl_set_object_lalign(obj,FL_ALIGN_BOTTOM or FL_ALIGN_INSIDE);
  66. fl_set_object_callback(obj,PFL_CALLBACKPTR(@return_cb),longint(PCounter));
  67. obj := fl_add_input(FL_NORMAL_INPUT,12,187,138,25,'');
  68. fdui^.obj[3] := obj;
  69. fl_set_object_lalign(obj,FL_ALIGN_LEFT or FL_ALIGN_INSIDE);
  70. fl_set_object_callback(obj,PFL_CALLBACKPTR(@return_cb),longint(Pinput));
  71. obj := fl_add_input(FL_NORMAL_INPUT,12,150,138,25,'');
  72. fdui^.obj[2] := obj;
  73. fl_set_object_callback(obj,PFL_CALLBACKPTR(@return_cb),longint(Pinput1));
  74. obj := fl_add_browser(FL_NORMAL_BROWSER,170,55,140,160,'');
  75. fdui^.br := obj;
  76. obj := fl_add_choice(FL_NORMAL_CHOICE,80,12,168,27,'');
  77. fdui^.when := obj;
  78. fl_set_object_callback(obj,PFL_CALLBACKPTR(@when_cb),0);
  79. obj := fl_add_button(FL_NORMAL_BUTTON,170,239,80,25,'Done');
  80. obj := fl_add_button(FL_NORMAL_BUTTON,70,239,80,25,'ResetLog');
  81. fl_set_object_callback(obj,PFL_CALLBACKPTR(@resetlog_cb),0);
  82. fl_end_form();
  83. fl_set_border_width(old_bw);
  84. create_form_form0:= fdui;
  85. end;
  86. begin
  87. fl_initialize(@argc, argv, 'FormDemo', nil, 0);
  88. fd_form0 := create_form_form0;
  89. { fill-in form initialization code }
  90. set_when(0);
  91. fl_set_object_dblbuffer(fd_form0^.br, 1);
  92. fl_addto_choice(fd_form0^.when,
  93. 'RETURN_END_CHANGED|RETURN_CHANGED|RETURN_END|RETURN_ALWAYS');
  94. { show the first form }
  95. fl_show_form(fd_form0^.form0, FL_PLACE_CENTER, FL_FULLBORDER, 'form0');
  96. fl_do_forms();
  97. end.