Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit PartyEdit;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TPartyEditFrame = class(TFrame)
- LBPK: TLabel;
- GroupBox1: TGroupBox;
- Label1: TLabel;
- Label5: TLabel;
- EditNameParty: TEdit;
- BtnPrev: TButton;
- BtnNext: TButton;
- BtnEdit: TButton;
- ComboBox1: TComboBox;
- procedure BtnPrevClick(Sender: TObject);
- procedure BtnNextClick(Sender: TObject);
- procedure BtnEditClick(Sender: TObject);
- procedure FrameEnter(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Procedure FillComponents();
- end;
- implementation
- {$R *.dfm}
- uses Party, BidirectionalParty, Main;
- var
- CurrentPartyIndex : Integer;
- Procedure FillCombobox(CB : TComboBox);
- begin
- CB.Clear;
- CB.Items.Add('Консерватизм');
- CB.Items.Add('Либерализм');
- CB.Items.Add('Социал-демократия');
- CB.Items.Add('Либертарианство');
- CB.Items.Add('Национализм');
- CB.Items.Add('Экологическое движение');
- CB.Items.Add('Консервативный либерализм');
- CB.Items.Add('Социальный консерватизм');
- CB.Items.Add('Социализм');
- CB.Items.Add('Коммунизм');
- end;
- Function GetParty() : TParty;
- var
- TempHead : PPartyList;
- CurrentPartyNode : TParty;
- Counter : Integer;
- begin
- TempHead := Main.PartyList.Head;
- CurrentPartyNode := NIL;
- Counter := 0;
- While TempHead <> NIL Do
- Begin
- if Counter = CurrentPartyIndex then
- begin
- CurrentPartyNode := TempHead.Party;
- break
- end
- else
- Inc(Counter);
- TempHead := TempHead^.Next;
- End;
- GetParty := CurrentPartyNode;
- end;
- Procedure TPartyEditFrame.FillComponents();
- var
- Party : TParty;
- PartyName : String;
- begin
- Party := GetParty;
- LBPK.Caption := Party.IdParty.ToString;
- EditNameParty.Text := Party.Name;
- ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(Party.PoliticalPosition);
- end;
- procedure TPartyEditFrame.FrameEnter(Sender: TObject);
- begin
- CurrentPartyIndex := 0;
- FillComponents;
- FillCombobox(ComboBox1);
- ComboBox1.ItemIndex := 0;
- end;
- procedure TPartyEditFrame.BtnEditClick(Sender: TObject);
- var
- NewParty : TParty;
- begin
- if EditNameParty.Text <> '' then
- begin
- try
- NewParty := TParty.Create(StrToInt(LBPK.Caption), EditNameParty.Text, Combobox1.Text);
- Main.PartyList.EditParty(NewParty);
- Application.MessageBox('Партия успешно отредактирована!','Редактирование партии', MB_OK + MB_ICONINFORMATION);
- Except
- On E : Exception do
- Application.MessageBox(PChar(E.Message),'Ошибка редактирования партии', MB_OK + MB_ICONSTOP);
- end;
- end
- else
- Application.MessageBox('Заполните все поля!','Редактирование партии',MB_OK+MB_ICONWARNING);
- end;
- procedure TPartyEditFrame.BtnNextClick(Sender: TObject);
- begin
- if CurrentPartyIndex <> Main.PartyList.Count - 1 then
- begin
- Inc(CurrentPartyIndex);
- FillComponents;
- end;
- end;
- procedure TPartyEditFrame.BtnPrevClick(Sender: TObject);
- begin
- if CurrentPartyIndex <> 0 then
- begin
- Dec(CurrentPartyIndex);
- FillComponents;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement