Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#10

AW: Objekte zur Laufzeit erzeugen

  Alt 19. Mai 2014, 15:45
Delphi-Quellcode:
unit Unit1;

...

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.GenerateButton;
  Form2.Show;
end;
Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls;

type
  TForm2 = class(TForm)
    PageControl1: TPageControl;
    TabAbrech: TTabSheet;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    BoxScro: TScrollBox;
    LBut: array[0..3] of TButton;
  public
    { Public-Deklarationen }
    procedure GenerateButton;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.GenerateButton;
var
  i: Integer;
begin
  BoxScro := TScrollBox.Create(TabAbrech);
  BoxScro.Parent := TabAbrech; //<<<<<<<<<<<<<<<<<<<<<
  BoxScro.Align := alClient;
  BoxScro.BorderStyle := bsNone;
  //FrmOpen.CDS.First;
  for i := 1 to High(Self.LBut) do //FrmOpen.CDS.RecNo do
  begin
    LBut[i] := TButton.Create(BoxScro);
    LBut[i].Parent := BoxScro;
    LBut[i].Left := 20 + ((LBut[i].Height + 10) * i);
    LBut[i].Height := 20;
    if (i >= 5) then
      LBut[i].Height := 20 + ((LBut[i].Height + 10) * i);
    LBut[i].Caption := IntToStr(LBut[i].Left); // FrmOpen.CDS.FieldByName('speise').Value;
    //FrmOpen.CDS.Next;
  end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  PageControl1.Align := alClient;
end;

end.
  Mit Zitat antworten Zitat