fbrowse.pp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. { This demo shows the use of a browser and a file selector.
  2. }
  3. program fbrowse;
  4. uses xforms,strings;
  5. var
  6. form : PFL_FORM;
  7. br : PFL_OBJECT;
  8. procedure load_file(ob : PFL_OBJECT; arg : longint);cdecl;
  9. var
  10. fname : pchar;
  11. begin
  12. fname := fl_show_fselector ('File To Load','','*.*','');
  13. if (fname = nil) then exit;
  14. if (fl_load_browser(br,fname)<>0) then
  15. fl_add_browser_line(br,'NO SUCH FILE!');
  16. end;
  17. procedure set_size(ob : PFL_OBJECT; arg : longint);cdecl;
  18. begin
  19. fl_set_browser_fontsize(br,arg);
  20. end;
  21. procedure exit_program(ob : PFL_OBJECT; data : longint);cdecl;
  22. begin
  23. halt(0);
  24. end;
  25. procedure create_form;
  26. var
  27. obj : PFL_OBJECT;
  28. x,dx : TFL_Coord;
  29. begin
  30. x := 20;
  31. dx := 85;
  32. form := fl_bgn_form(FL_NO_BOX,590,610);
  33. obj := fl_add_box(FL_UP_BOX,0,0,590,610,'');
  34. obj := fl_add_browser(FL_NORMAL_BROWSER,20,20,550,530,'');
  35. br := obj ;
  36. obj := fl_add_button(FL_NORMAL_BUTTON,x,560,dx,30,'Load');
  37. fl_set_object_callback(obj,PFL_CALLBACKPTR(@load_file),0);
  38. x :=x+ dx + 10;
  39. obj := fl_add_lightbutton(FL_RADIO_BUTTON,x,560,dx,30,'Tiny');
  40. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_size),FL_TINY_SIZE);
  41. x := x+dx;
  42. obj := fl_add_lightbutton(FL_RADIO_BUTTON,x ,560,dx,30,'Small');
  43. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_size),FL_SMALL_SIZE);
  44. { Compiler crashes on the next one. Probably the comparing of the
  45. constants..
  46. if (longint(FL_SMALL_SIZE)=longint(FL_BROWSER_FONTSIZE)) then
  47. fl_set_button(obj, 1);
  48. } x := x+dx;
  49. obj := fl_add_lightbutton(FL_RADIO_BUTTON,x ,560,dx,30,'Normal');
  50. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_size),FL_NORMAL_SIZE);
  51. { idem here.
  52. if FL_NORMAL_SIZE = FL_BROWSER_FONTSIZE then
  53. fl_set_button(obj,1 );
  54. } x := x+dx;
  55. obj := fl_add_lightbutton(FL_RADIO_BUTTON,x ,560,dx,30,'Large');
  56. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_size),FL_LARGE_SIZE);
  57. obj := fl_add_button(FL_NORMAL_BUTTON,470,560,100,30,'Exit');
  58. fl_set_object_callback(obj,PFL_CALLBACKPTR(@exit_program), 0);
  59. fl_end_form();
  60. end;
  61. begin
  62. fl_initialize(@argc, argv, 'FormDemo', nil, 0);
  63. create_form();
  64. fl_clear_browser(br);
  65. fl_add_browser_line(br,'LOAD A FILE.');
  66. fl_set_browser_fontstyle(br,FL_FIXED_STYLE);
  67. fl_show_form(form,FL_PLACE_FREE,FL_FULLBORDER,'Browser');
  68. fl_do_forms();
  69. fl_hide_form(form);
  70. fl_free_form(form);
  71. end.