Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.96 KB | None | 0 0
  1.  
  2. type
  3.   TFormInstr = record
  4.     Panel: TPanel;
  5.     Control: TComboBox;
  6.     Elements: array of TComboBox;
  7.   end;
  8.  
  9. var
  10.   frm: TForm;
  11.   addbtn, storeBtn: TButton;
  12.   instr: array of TFormInstr;
  13.  
  14. const
  15.   CoreInstr = ['Withdraw', 'Deposit', 'Use', 'Cast'];
  16.   MiscInstr = ['Object 1', 'Item 1', 'Item 2', 'Button 1'];
  17.  
  18. function NewFormInstr(Parent: TComponent): TFormInstr;
  19. begin
  20.   Result.Panel.Init(Parent);
  21.   Result.Panel.SetParent(Parent);
  22.   Result.Panel.SetAlign(alTop);
  23.   Result.Panel.SetBevelOuter(bvNone);
  24.  
  25.   Result.Control.Init(Result.Panel);
  26.   Result.Control.SetParent(Result.Panel);
  27.   Result.Control.SetAlign(alRight);
  28.   Result.Control.SetWidth(frm.GetWidth div 3);
  29.   Result.Control.SetReadOnly(True);
  30.  
  31.   Instr += Result;
  32. end;
  33.  
  34. function TFormInstr.NewCombo(): TComboBox;
  35. begin
  36.   Result.Init(Self.Panel);
  37.   Result.SetParent(Self.Panel);
  38.   Result.SetAlign(alRight);
  39.   Result.SetWidth(frm.GetWidth div 3);
  40.   Result.SetReadOnly(True);
  41.  
  42.   Self.Elements += Result;
  43. end;
  44.  
  45. function CreatePanel(Parent: TComponent): TFormInstr;
  46. var
  47.   combo: TComboBox;
  48.   i: Int32;
  49. begin
  50.   Result := NewFormInstr(Parent);
  51.  
  52.   with Result.Control.GetItems() do
  53.     for i:=0 to High(CoreInstr) do
  54.       Add(CoreInstr[i]);
  55.  
  56.   with Result.NewCombo().GetItems() do
  57.     for i:=0 to High(MiscInstr) do
  58.       Add(MiscInstr[i]);
  59.  
  60.   with Result.NewCombo().GetItems() do
  61.     for i:=0 to High(MiscInstr) do
  62.       Add(MiscInstr[i]);
  63.  
  64.   Result.Panel.SetHeight(Result.Control.GetHeight());
  65. end;
  66.  
  67. procedure Add(Self, Sender: TObject);
  68. begin
  69.   CreatePanel(frm);
  70. end;
  71.  
  72. procedure test;
  73. begin
  74.   frm.init(nil);
  75.  
  76.   storeBtn.Init(frm);
  77.   storeBtn.SetCaption('Save');
  78.   storeBtn.setParent(frm);
  79.   storeBtn.setAlign(alTop);
  80.   storeBtn.setOnClick(@add);
  81.  
  82.   addBtn.Init(frm);
  83.   addBtn.SetCaption('New instruction');
  84.   addBtn.setParent(frm);
  85.   addBtn.setAlign(alTop);
  86.   addBtn.setOnClick(@add);
  87.  
  88.   createPanel(frm);
  89.  
  90.   frm.ShowModal;
  91. end;
  92.  
  93. begin
  94.   Sync(@test);
  95. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement