-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lists.pas
136 lines (119 loc) · 3.57 KB
/
Lists.pas
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
unit Lists;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, System.Types,
Vcl.Menus, System.UITypes;
type
TFormList = class(TForm)
Grid: TStringGrid;
MainMenu: TMainMenu;
MenuFile: TMenuItem;
SubSaveAs: TMenuItem;
SaveFile: TSaveDialog;
procedure FormShow(Sender: TObject);
procedure GridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure SubSaveAsClick(Sender: TObject);
private
public
procedure SortGrid;
procedure CalculateSp;
end;
var
FormList: TFormList;
implementation
{$R *.dfm}
{$SetPEFlags IMAGE_FILE_RELOCS_STRIPPED}
{$SetPEFlags IMAGE_FILE_LINE_NUMS_STRIPPED}
{$SetPEFlags IMAGE_FILE_LOCAL_SYMS_STRIPPED}
{$SetPEFlags IMAGE_FILE_DEBUG_STRIPPED}
{$SetPEFlags IMAGE_FILE_EXECUTABLE_IMAGE}
uses Main, PositionList;
procedure TFormList.FormShow(Sender: TObject);
begin
Grid.Cells[0, 0]:='Rang';
Grid.Cells[1, 0]:='Alternativa';
Grid.Cells[2, 0]:='Sn';
Grid.Cells[3, 0]:='Rn';
end;
procedure TFormList.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
CellString: string;
Format: Integer;
begin
Format:=(DT_VCENTER Or DT_CENTER Or DT_SINGLELINE);
CellString:=Grid.Cells[ACol, ARow];
Grid.Canvas.Brush.Color:=Main.Config.Bg;
Grid.Canvas.Font.Color:=Main.Config.Font;
Grid.Canvas.Font.Name:=Main.Config.FontName;
Grid.Canvas.Font.Style:=[];
Grid.Canvas.Pen.Color:=clBlack;
Grid.Canvas.Pen.Width:=2;
If (gdSelected In State) Then
begin
Grid.Canvas.Brush.Color:=Main.Config.Font;
Grid.Canvas.Font.Color:=Main.Config.Bg;
end
Else
If (gdFixed In State) Then
begin
Grid.Canvas.Brush.Color:=$00FF9900;
Grid.Canvas.Font.Color:=clWhite;
Grid.Canvas.Font.Style:=[fsBold];
end;
Grid.Canvas.FillRect(Rect);
DrawText(Grid.Canvas.Handle, CellString, CellString.Length, Rect, Format);
Grid.Canvas.MoveTo(Rect.Left, Rect.Top);
Grid.Canvas.LineTo(Rect.Right, Rect.Top);
Grid.Canvas.MoveTo(Rect.Right, Rect.Top);
Grid.Canvas.LineTo(Rect.Right, Rect.Bottom);
end;
procedure TFormList.SubSaveAsClick(Sender: TObject);
begin
If SaveFile.Execute Then
begin
Main.FormMain.SaveAsHTML(Grid, ChangeFileExt(SaveFile.FileName, '.html'));
MessageBeep(MB_ICONINFORMATION);
MessageDlg('Datoteka je uspešno sačuvana.', mtInformation, [mbOK], 0, mbOK);
end;
end;
procedure TFormList.SortGrid;
var
I, J: Integer;
Sn, Rn: string;
Alt: string;
begin
CalculateSp;
For I:=1 To Grid.RowCount-1 Do
For J:=I+1 To Grid.RowCount-1 Do
If (Grid.Cells[2, I].ToDouble>Grid.Cells[2, J].ToDouble) Then
begin
Alt:=Grid.Cells[1, I];
Sn:=Grid.Cells[2, I];
Rn:=Grid.Cells[3, I];
Grid.Cells[1, I]:=Grid.Cells[1, J];
Grid.Cells[2, I]:=Grid.Cells[2, J];
Grid.Cells[3, I]:=Grid.Cells[3, J];
Grid.Cells[1, J]:=Alt;
Grid.Cells[2, J]:=Sn;
Grid.Cells[3, J]:=Rn;
end;
end;
procedure TFormList.CalculateSp;
var
I: Integer;
MaxS, MinS, MaxR, MinR, Sp: Double;
begin
MaxS:=Grid.Cells[2, 1].ToDouble;
MinS:=Grid.Cells[2, Grid.RowCount-1].ToDouble;
MaxR:=Grid.Cells[3, 1].ToDouble;
MinR:=Grid.Cells[3, Grid.RowCount-1].ToDouble;
For I:=1 To Grid.RowCount-1 Do
begin
Sp:=((Grid.Cells[2, I].ToDouble-MaxS)/(MinS-MaxS))+((Grid.Cells[3,I].toDouble-MaxR)/(MinR-MaxR));
PositionList.FormPosition.Grid.Cells[2, I]:=FormatFloat('0.000', Sp);
end;
end;
end.