tstelgtk.pp 3.5 KB

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