Recent

Author Topic: Event log window component.  (Read 443 times)

TomTom

  • Full Member
  • ***
  • Posts: 170
Event log window component.
« on: October 10, 2022, 01:03:28 pm »
I'm wondering is there any ready to use, visual component that is suited for log(event) window just like Lazarus Messages window, or, I will have to write it myself. For now I'm using TMemo and is ok, but it would be nice to be able to add some small images/icons to text :)

ASerge

  • Hero Member
  • *****
  • Posts: 2049
Re: Event log window component.
« Reply #1 on: October 10, 2022, 10:08:20 pm »
I'm wondering is there any ready to use, visual component that is suited for log(event) window just like Lazarus Messages window, or, I will have to write it myself. For now I'm using TMemo and is ok, but it would be nice to be able to add some small images/icons to text :)
You can use a combination of controls.
Example in a new application: place a Panel (Align=alRight) with Button on it, a ScrollBox (Align=alClient) in the Form and this code:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     Button1: TButton;
  13.     Panel1: TPanel;
  14.     ScrollBox1: TScrollBox;
  15.     procedure Button1Click(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.  
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. uses StrUtils, LCLType, LCLIntf;
  30.  
  31. procedure AddTextToLog(const AText: string; AIcon: HICON; ToScroll: TScrollBox);
  32. const
  33.   CPanelHeight = 32;
  34. var
  35.   Owner: TComponent;
  36.   Panel: TPanel;
  37.   Memo: TMemo;
  38.   Image: TImage;
  39.   Bevel: TBevel;
  40. begin
  41.   Owner := ToScroll.Owner;
  42.   // Panel
  43.   Panel := TPanel.Create(Owner);
  44.   Panel.Align := alTop;
  45.   Panel.BevelOuter := bvNone;
  46.   Panel.Height := CPanelHeight;
  47.   Panel.Top := MaxInt;
  48.   // Image
  49.   Image := TImage.Create(Owner);
  50.   Image.Align := alLeft;
  51.   Image.Width := CPanelHeight;
  52.   Image.Transparent := True;
  53.   Image.Stretch := True;
  54.   Image.Picture.Icon.Handle := AIcon;
  55.   Image.Parent := Panel;
  56.   // Memo
  57.   Memo := TMemo.Create(Owner);
  58.   Memo.Align := alClient;
  59.   Memo.BorderStyle := bsNone;
  60.   Memo.ParentColor := True;
  61.   Memo.ReadOnly := True;
  62.   Memo.Text := AText;
  63.   Memo.Parent := Panel;
  64.   // Bevel
  65.   Bevel := TBevel.Create(Owner);
  66.   Bevel.Align := alTop;
  67.   Bevel.Shape := bsTopLine;
  68.   Bevel.Height := 2;
  69.   Bevel.Top := MaxInt;
  70.   //
  71.   Panel.Parent := ToScroll;
  72.   Bevel.Parent := ToScroll;
  73. end;
  74.  
  75.  
  76. procedure TForm1.Button1Click(Sender: TObject);
  77. const
  78.   IDI_ERROR = MAKEINTRESOURCE(32513);
  79.   IDI_QUESTION = MAKEINTRESOURCE(32514);
  80.   IDI_WARNING = MAKEINTRESOURCE(32515);
  81.   IDI_INFORMATION = MAKEINTRESOURCE(32516);
  82.   IDI_WINLOGO = MAKEINTRESOURCE(32517);
  83. begin
  84.   AddTextToLog(DupeString('Test of Information', 7),
  85.     LCLIntf.LoadIcon(0, IDI_INFORMATION),
  86.     ScrollBox1);
  87.   AddTextToLog(DupeString('Test of Question', 8),
  88.     LCLIntf.LoadIcon(0, IDI_QUESTION),
  89.     ScrollBox1);
  90.   AddTextToLog(DupeString('Test of Warning', 9),
  91.     LCLIntf.LoadIcon(0, IDI_WARNING),
  92.     ScrollBox1);
  93.   AddTextToLog(DupeString('Test of Error', 10),
  94.     LCLIntf.LoadIcon(0, IDI_ERROR),
  95.     ScrollBox1);
  96.   AddTextToLog(DupeString('Test of Logo', 11),
  97.     LCLIntf.LoadIcon(0, IDI_WINLOGO),
  98.     ScrollBox1);
  99. end;
  100.  
  101. end.

jamie

  • Hero Member
  • *****
  • Posts: 5068
Re: Event log window component.
« Reply #2 on: October 11, 2022, 02:52:49 am »
The TLazLoggerFile class isn't helpful ?
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018