File: main.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (100 lines) | stat: -rw-r--r-- 2,352 bytes parent folder | download | duplicates (3)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
unit main;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Forms, Controls, Grids, ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    ImageList1: TImageList;
    RadioGroup1: TRadioGroup;
    StringGrid1: TStringGrid;
    procedure RadioGroup1Click(Sender: TObject);
    procedure StringGrid1HeaderClick(
      Sender: TObject; IsColumn: Boolean;Index: Integer);
  private
    procedure AdjustTitleHeight;
    procedure Refresh;
  public

  end; 

var
  Form1: TForm1; 

implementation

{$R main.lfm}

uses
  Buttons;

{ TForm1 }

procedure TForm1.AdjustTitleHeight;
begin
  if RadioGroup1.ItemIndex < 2 then
    StringGrid1.RowHeights[0] := StringGrid1.DefaultRowHeight
  else
    StringGrid1.RowHeights[0] := StringGrid1.RowHeights[1] + ImageList1.Height;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to StringGrid1.Columns.Count - 1 do begin
    if RadioGroup1.ItemIndex>1 then
      StringGrid1.RowHeights[0] := 2*StringGrid1.DefaultRowHeight
    else
      StringGrid1.RowHeights[0] := StringGrid1.DefaultRowHeight;
    StringGrid1.Columns[i].Title.ImageLayout :=
      TButtonLayout(RadioGroup1.ItemIndex);
  end;
  AdjustTitleHeight;
end;

procedure TForm1.Refresh;
var
  i, j: Integer;
  t: String;
begin
  with StringGrid1 do
    for i := 1 to RowCount - 2 do
      for j := i + 1 to RowCount - 1 do begin
        if
          (Columns[0].Title.ImageIndex = 1) and (Cells[1, i] > Cells[1, j]) or
          (Columns[0].Title.ImageIndex = 2) and (Cells[1, i] < Cells[1, j]) or
          (Columns[1].Title.ImageIndex = 1) and (StrToInt(Cells[2, i]) > StrToInt(Cells[2, j])) or
          (Columns[1].Title.ImageIndex = 2) and (StrToInt(Cells[2, i]) < StrToInt(Cells[2, j]))
        then begin
          t := Cells[1, i]; Cells[1, i] := Cells[1, j]; Cells[1, j] := t;
          t := Cells[2, i]; Cells[2, i] := Cells[2, j]; Cells[2, j] := t;
        end;
      end;
end;

procedure TForm1.StringGrid1HeaderClick(
  Sender: TObject; IsColumn: Boolean; Index: Integer);
begin
  if not IsColumn then exit;
  with StringGrid1.Columns[Index - 1].Title do begin
    if ImageIndex = 2 then
      ImageIndex := 0
    else
      ImageIndex := ImageIndex + 1;
    if ImageIndex > 0 then
      StringGrid1.Columns[2 - Index].Title.ImageIndex := 0;
  end;
  AdjustTitleHeight;
  Refresh;
end;

end.