tstelgtk.pp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {$mode objfpc}
  2. {$H+}
  3. {$apptype gui}
  4. program tstelgtk;
  5. uses gdk,gtk,fpgtk,fpgtkext,classes,sysutils,eventlog;
  6. { ---------------------------------------------------------------------
  7. Main form class
  8. ---------------------------------------------------------------------}
  9. Type
  10. TMainForm = Class(TFPGtkWindow)
  11. FEventLog : TEventLog;
  12. RGFrame : TFPgtkFrame;
  13. FHBox : TFPgtkHBox;
  14. RGBox,
  15. FVBox : TFPgtkVBox;
  16. BSend : TFPgtkButton;
  17. RGMsgType : TFPgtkRadioButtonGroup;
  18. FLMsg : TFPGtkLabel;
  19. FMsg : TFPGtkEntry;
  20. Procedure BSendClicked(Sender : TFPgtkObject; Data : Pointer);
  21. Public
  22. Constructor Create;
  23. Destructor Destroy; override;
  24. Procedure CreateWindow;
  25. Procedure SendEvent;
  26. end;
  27. ResourceString
  28. SCaption = 'Free Pascal Event Log Demo';
  29. SEventlogDemo = 'TestEventlogClass';
  30. SMessage = 'Message text:';
  31. SMsgType = 'Message type:';
  32. SSend = 'Send message';
  33. SInformation = 'Information';
  34. SWarning = 'Warning';
  35. SError = 'Error';
  36. SDebug = 'Debug';
  37. { ---------------------------------------------------------------------
  38. Form Creation
  39. ---------------------------------------------------------------------}
  40. Constructor TMainForm.Create;
  41. begin
  42. Inherited create (gtk_window_dialog);
  43. Createwindow;
  44. end;
  45. Procedure TMainForm.CreateWindow;
  46. Procedure AddRG(C : String);
  47. Var
  48. RB : TFPgtkRadioButton;
  49. begin
  50. RB:= TFPgtkRadioButton.CreateWithLabel(RGmsgType,C);
  51. RGBox.Packstart(RB,False,False,2);
  52. rb.TheLabel.Justify:=GTK_JUSTIFY_LEFT;
  53. end;
  54. Var
  55. S : TStrings;
  56. begin
  57. BSend:=TFPGtkButton.CreateWithlabel(SSend);
  58. BSend.ConnectCLicked(@BSendClicked,Nil);
  59. RGFrame:=TFpgtkFrame.Create;
  60. RGFrame.Text:=SMsgType;
  61. RGBox:=TFPgtkVBox.Create;
  62. RGFRame.Add(RGBox);
  63. S:=TstringList.Create;
  64. try
  65. With S do
  66. begin
  67. Add(SInformation);
  68. Add(SWarning);
  69. Add(SError);
  70. Add(SDebug);
  71. end;
  72. RGMsgType:=RadioButtonGroupCreateFromStrings(S,Nil);
  73. RGMsgType.PackInBox(RGBox,True,False,False,2);
  74. Finally
  75. S.Free;
  76. end;
  77. FLMsg:=TfpGtkLabel.Create(SMessage);
  78. FMsg:=TfpGtkEntry.Create;
  79. FHBox:=TFPgtkHbox.Create;
  80. FHBox.PackStart(FLMsg,False,False,2);
  81. FHBox.PackStart(FMsg,True,True,2);
  82. Title:=SCaption;
  83. FVBox:=TFPgtkVBox.Create;
  84. FVBox.Homogeneous:=False;
  85. FVBox.PackStart(FHBox,False,False,2);
  86. FVBox.PackStart(RGFrame,False,False,2);
  87. FVBox.PackStart(BSend,true,false,2);
  88. Add(FVBox);
  89. FMsg.GrabFocus;
  90. FEventLog:=TEventlog.Create(Nil);
  91. FEventLog.Identification:=SEventLogDemo;
  92. FEventLog.RegisterMessagefile('');
  93. FEventLog.Active:=True;
  94. end;
  95. Destructor TMainForm.Destroy;
  96. begin
  97. FEventLog.Active:=False;
  98. FEventLog.Free;
  99. Inherited;
  100. end;
  101. { ---------------------------------------------------------------------
  102. Callback events
  103. ---------------------------------------------------------------------}
  104. Procedure TMainForm.BSendClicked(Sender : TFPgtkObject; Data : Pointer);
  105. begin
  106. SendEvent;
  107. end;
  108. Procedure TMainForm.SendEvent;
  109. Var
  110. E : TEventType;
  111. begin
  112. Case RGMsgType.ActiveButtonIndex of
  113. 0 : E:=etinfo;
  114. 1 : E:=etWarning;
  115. 2 : E:=etError;
  116. 3 : E:=etDebug;
  117. end;
  118. FEventLog.log(E,FMsg.Text);
  119. end;
  120. { ---------------------------------------------------------------------
  121. Program.
  122. ---------------------------------------------------------------------}
  123. begin
  124. application := TFPgtkApplication.Create;
  125. application.MainWindow := TMainForm.Create;
  126. application.Run;
  127. application.Free;
  128. end.