File: test4_3listview.lpr

package info (click to toggle)
lazarus 2.2.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,980 kB
  • sloc: pascal: 1,944,919; xml: 357,634; makefile: 270,608; cpp: 57,115; sh: 3,249; java: 609; perl: 297; sql: 222; ansic: 137
file content (85 lines) | stat: -rw-r--r-- 2,511 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
 *****************************************************************************
 *                                                                           *
 *  This file is part of the Lazarus Component Library (LCL)                 *
 *                                                                           *
 *  See the file COPYING.LCL, included in this distribution,                 *
 *  for details about the copyright.                                         *
 *                                                                           *
 *  This program is distributed in the hope that it will be useful,          *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
 *                                                                           *
 *****************************************************************************

  LCL Test 4_3

  Showing a TListView.
}
program test4_3listview;

{$mode objfpc}{$H+}

uses
  Interfaces, FPCAdds, LCLProc, LCLType, Classes, Controls, Forms, TypInfo,
  LMessages, Buttons, ExtCtrls, ComCtrls, SynEdit, SynHighlighterPas,
  Graphics;

type

  { TForm1 }

  TForm1 = class(TForm)
    ListView1: TListView;
    procedure Form1Create(Sender: TObject);
  public
    constructor Create(TheOwner: TComponent); override;
    procedure AddListViewItem(const ACaption, SomeSubItems: string);
  end;

{ TForm1 }

procedure TForm1.Form1Create(Sender: TObject);
begin
  debugln('TForm1.Form1Create ',DbgSName(Sender));
  SetBounds(50,50,500,400);

  ListView1:=TListView.Create(Self);
  with ListView1 do begin
    Name:='ListView1';
    Align:=alTop;
    Height:=200;
    Parent:=Self;
    ViewStyle:=vsReport;
  end;
  ListView1.Columns.Add.Caption:='Name';
  ListView1.Columns.Add.Caption:='Column 2';
  ListView1.Columns.Add.Caption:='Column 3';
  AddListViewItem('First','A1'+LineEnding+'A2');
  AddListViewItem('Second','B1'+LineEnding+'B2');
  AddListViewItem('Third','C1'+LineEnding+'C2');
end;

constructor TForm1.Create(TheOwner: TComponent);
begin
  OnCreate:=@Form1Create;
  inherited Create(TheOwner);
end;

procedure TForm1.AddListViewItem(const ACaption, SomeSubItems: string);
var
  NewItem: TListItem;
begin
  NewItem:=ListView1.Items.Add;
  NewItem.Caption:=ACaption;
  NewItem.SubItems.Text:=SomeSubItems;
end;

var
  Form1: TForm1 = nil;
begin
  Application.Initialize;
  Application.CreateForm(TForm1,Form1);
  Application.Run;
end.