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
| unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs;
type
TMyData = class
private
FB: integer;
FA: integer;
procedure SetA(const Value: integer);
procedure SetB(const Value: integer);
public
property A:integer read FA write SetA;
property B:integer read FB write SetB;
end;
TMyList = class(TStringList)
private
function GetMyData(index: integer): TMyData;
public
property Data[index: integer]:TMyData read GetMyData;
function addData(xA,xB: integer):integer;
procedure deleteData(index: integer);
procedure ClearData;
procedure ShowData(ALines: TStrings);
procedure process;
end;
implementation
{ TMyData }
procedure TMyData.SetB(const Value: integer);
begin
FB := Value;
end;
procedure TMyData.SetA(const Value: integer);
begin
FA := Value;
end;
{ TMyList }
function TMyList.addData(xA, xB: integer): integer;
var
AData: TMyData;
begin
AData := TMyData.Create;
with AData do
begin
FA := xA;
FB := xB;
end;
Result := Self.AddObject('',AData);
end;
procedure TMyList.ClearData;
var
I: integer;
begin
for I := Pred(Self.Count) downto 0 do
begin
TMyData(Self.Objects[i]).Free;
Self.Delete(I);
end;
end;
procedure TMyList.deleteData(index: integer);
begin
if Self.Count > 0
then
if index in [0..Self.Count-1] then
begin
TMyData(Self.Objects[index]).Free;
Self.Delete(index);
end;
end;
function TMyList.GetMyData(index: integer): TMyData;
begin
Result := nil;
if Self.Count > 0
then
if index in [0..Self.Count-1] then
Result := TMyData(Self.Objects[index]);
end;
procedure TMyList.process;
var
I: integer;
begin
for I := Pred(Self.Count) downto 0 do
if Assigned(Self.Data[i])
then
if Abs(Self.Data[i].FA - Self.Data[i].FB) = 5
then Self.deleteData(I);
end;
procedure TMyList.ShowData(ALines: TStrings);
var
I: integer;
begin
ALines.Clear;
ALines.BeginUpdate;
try
for I := 0 to Pred(Self.Count) do
if Assigned(Self.Data[i]) then
ALines.Add(IntToStr(Self.Data[i].FA)+' '+
IntToStr(Self.Data[i].FB));
finally
ALines.EndUpdate;
end;
end;
end. |
Partager