Advertisement
Matixs

Untitled

May 31st, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.04 KB | None | 0 0
  1. unit PartyView;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  7.   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, BidirectionalParty,
  8.   Vcl.Grids, Vcl.StdCtrls;
  9.  
  10. const
  11.     HEADER_ID = '№';
  12.     HEADER_NAME = 'Название партии';
  13.     HEADER_POSITION = 'Политическая позиция';
  14.  
  15. type
  16.   TPartyViewFrame = class(TFrame)
  17.     GroupBox1: TGroupBox;
  18.     SG: TStringGrid;
  19.     procedure FrameEnter(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.     Constructor Create(aOwner : TComponent); override;
  25.   end;
  26.  
  27. implementation
  28.  
  29. {$R *.dfm}
  30.  
  31. uses Main;
  32.  
  33. Constructor TPartyViewFrame.Create(aOwner: TComponent);
  34. begin
  35.     inherited Create(aOwner);
  36. end;
  37.  
  38. procedure ClearStringGrid(SG : TStringGrid);
  39. var
  40.     I, J : Integer;
  41. begin
  42.     for I := 0 to SG.RowCount - 1 do
  43.     begin
  44.         SG.Rows[I].Clear;
  45.     end;
  46. end;
  47.  
  48. procedure FillHeadersSG(SG : TStringGrid);
  49. begin
  50.     SG.Cells[0,0] := HEADER_ID;
  51.     SG.Cells[1,0] := HEADER_NAME;
  52.     SG.Cells[2,0] := HEADER_POSITION;
  53.     SG.ColWidths[0] := 50;
  54.     SG.ColWidths[1] := 600;
  55.     SG.ColWidths[2] := 600;
  56. end;
  57.  
  58. Procedure FillStringGrid(SG : TStringGrid);
  59. var
  60.     I, J : Integer;
  61.     TempHead : PPartyList;
  62. begin
  63.     ClearStringGrid(SG);
  64.     FillHeadersSG(SG);
  65.     TempHead := Main.PartyList.Head;
  66.  
  67.     I := 1;
  68.     J := 0;
  69.  
  70.     SG.RowCount := Main.PartyList.Count + 1;
  71.  
  72.     // Цикл для прохода по списку
  73.     while TempHead <> NIL do
  74.     begin
  75.         with SG do
  76.         begin
  77.             Cells[J, I] := (TempHead^.Party.IdParty + 1).ToString;
  78.             Cells[J + 1, I] := TempHead^.Party.Name;
  79.             Cells[J + 2, I] := TempHead^.Party.PoliticalPosition;
  80.         end;
  81.         Inc(I);
  82.         TempHead := TempHead^.Next; // Переход к следующей записи
  83.     end;
  84.  
  85.     Dispose(TempHead);
  86. end;
  87.  
  88. procedure TPartyViewFrame.FrameEnter(Sender: TObject);
  89. begin
  90.     FillStringGrid(SG);
  91. end;
  92.  
  93. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement