Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.74 KB | None | 0 0
  1. unit List;
  2.  
  3. interface
  4.  
  5. uses VCL.GRIDS, System.SysUtils;
  6.  
  7. type
  8.    TList = class(TObject)
  9.    private
  10.       FNext: TList;
  11.       FVal: Integer;
  12.       FCount: Integer;
  13.    public
  14.       constructor Create; overload;
  15.       destructor Destroy; overload;
  16.  
  17.       procedure Add(pVal: Integer);
  18.       procedure AddFromSG(sgE: TStringGrid);
  19.       procedure Show(E: TStringGrid);
  20.       procedure SetNext(Next: TList);
  21.  
  22.       property Next: TList read FNext write SetNext;
  23.       property Val: Integer read FVal;
  24.  
  25.    end;
  26.  
  27. implementation
  28.  
  29. constructor TList.Create;
  30. begin
  31.    inherited;
  32.    FNext := nil;
  33.    FCount := 0;
  34. end;
  35.  
  36. destructor TList.Destroy;
  37. begin
  38.    if FNext <> nil then
  39.       FNext.Destroy;
  40.    inherited Destroy;
  41. end;
  42.  
  43. procedure TList.SetNext(Next: TList);
  44. begin
  45.    FNext := Next;
  46. end;
  47.  
  48. procedure TList.Add(pVal: Integer);
  49. var
  50.    Temp: TList;
  51. begin
  52.    Temp := Self;
  53.    while Temp.FNext <> nil do
  54.       Temp := Temp.FNext;
  55.    Temp.FNext := TList.Create;
  56.    Temp.FNext.FVal := pVal;
  57.    Inc(FCount);
  58. end;
  59.  
  60. procedure TList.AddFromSG(sgE: TStringGrid);
  61. var
  62.    Temp: TList;
  63.    I: Integer;
  64. begin
  65.    Temp := Self;
  66.    while Temp.FNext <> nil do
  67.       Temp := Temp.FNext;
  68.    with sgE do
  69.    begin
  70.       for I := 0 to ColCount - 1 do
  71.       begin
  72.          Temp.FNext := TList.Create;
  73.          Temp.FNext.FVal := StrToInt(Cells[I, 0]);
  74.          Temp := Temp.FNext;
  75.          Inc(FCount);
  76.       end;
  77.    end;
  78. end;
  79.  
  80. procedure TList.Show(E: TStringGrid);
  81. var
  82.    I: Integer;
  83.    Temp: TList;
  84. begin
  85.    Temp := FNext;
  86.    with E do
  87.    begin
  88.       ColCount := FCount;
  89.       for I := 0 to ColCount - 1 do
  90.       begin
  91.          Cells[I, 0] := IntToStr(Temp.FVal);
  92.          Temp := Temp.FNext;
  93.       end;
  94.    end;
  95. end;
  96.  
  97. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement