title image


Smiley Re: Objekt zur Laufzeit kopieren
Hi,





Hier mal ein Auszug aus meinem Quelltext:



procedure TfrmKennzahlen.OperatorenErstellen(ActIndex: integer);

var

NewTop: Integer;



function CrtShape(FeldName: string): TShape;

var

PrevShape, ActShape: TShape;

begin

PrevShape := TShape(FindComponent(FeldName + intToStr(ActIndex-1)));

ActShape := TShape.Create(Self);

ActShape.Parent := scrbxDaten02;

ActShape.Name := FeldName + IntToStr(ActIndex);

ActShape.SetBounds(PrevShape.Left, PrevShape.Top + PrevShape.Height + 40, PrevShape.Width, PrevShape.Height);

ActShape.Brush.Color := clBtnFace;

NewTop := PrevShape.Top + 160 + PrevShape.Height;

Result := ActShape;

end;



function CrtEdtField(FeldName: string): TEdit;

var

PrevEdtField, ActField: TEdit;

begin

PrevEdtField := TEdit(FindComponent(FeldName + intToStr(ActIndex-1)));

ActField := TEdit.Create(Self);

ActField.Parent := scrbxDaten02;

ActField.Name := FeldName + IntToStr(ActIndex);

ActField.Text := '';

ActField.OnKeyPress := edtKeyPress;

ActField.SetBounds(PrevEdtField.Left, PrevEdtField.Top + Shape_1.Height + 40, PrevEdtField.Width,

PrevEdtField.Height);

ActField.MaxLength := PrevEdtField.MaxLength;

Result := ActField;

end;



procedure CrtPanel(FeldName: string);

var

PrevPanel, ActPanel: TPanel;

begin

PrevPanel := TPanel(FindComponent(FeldName + intToStr(ActIndex-1)));

ActPanel := TPanel.Create(Self);

ActPanel.Parent := scrbxDaten02;

ActPanel.Name := FeldName + IntToStr(ActIndex);

ActPanel.SetBounds(PrevPanel.Left, PrevPanel.Top + Shape_1.Height + 40, PrevPanel.Width, PrevPanel.Height);

ActPanel.Caption := PrevPanel.Caption;

end;



function CrtLabel(FeldName: string): TLabel;

var

PrevLabel, ActLabel: TLabel;

begin

PrevLabel := TLabel(FindComponent(FeldName + intToStr(ActIndex-1)));

ActLabel := TLabel.Create(Self);

ActLabel.Parent := scrbxDaten02;

ActLabel.Name := FeldName + IntToStr(ActIndex);

ActLabel.SetBounds(PrevLabel.Left, PrevLabel.Top + Shape_1.Height + 40, PrevLabel.Width, PrevLabel.Height);

ActLabel.Caption := '';

ActLabel.BringToFront;

Result := ActLabel;

end;



function CrtBitBtn(FeldName: string): TButton;

var

PrevButton, ActButton: TBitBtn;

begin

PrevButton := TBitBtn(FindComponent(FeldName + intToStr(ActIndex-1)));

ActButton := TBitBtn.Create(Self);

ActButton.Parent := scrbxDaten02;

ActButton.Name := FeldName + IntToStr(ActIndex);

ActButton.SetBounds(PrevButton.Left, PrevButton.Top + Shape_1.Height + 40, PrevButton.Width, PrevButton.Height);

ActButton.Caption := '';

ActButton.Glyph := PrevButton.Glyph;

Result := ActButton;

end;



function CrtCombobox(FeldName: string): TComboBox;

var

PrevComboBox, ActComboBox: TComboBox;

begin

PrevComboBox := TComboBox(FindComponent(FeldName + intToStr(ActIndex-1)));

ActComboBox := TComboBox.Create(Self);

ActComboBox.Parent := scrbxDaten02;

ActComboBox.Name := FeldName + IntToStr(ActIndex);

ActComboBox.SetBounds(PrevComboBox.Left, PrevComboBox.Top + Shape_1.Height + 40, PrevComboBox.Width,

PrevComboBox.Height);

ActComboBox.Text := '';

ActComboBox.Font.Size := PrevComboBox.Font.Size;

ActComboBox.Font.Style := PrevComboBox.Font.Style;

ActComboBox.Items.Assign(PrevComboBox.Items);

Result := ActComboBox;

end;



begin



if FindComponent('Shape_' + intToStr(ActIndex)) = nil then

begin // Wenn nicht dann anlegen

Inc(AnzahlOperatoren);



CrtShape('Shape_');



CrtBitBtn('btbtnQRotate_').OnClick := btbtnQRotate_1Click;

CrtLabel('lblNenner_').Visible := false;

CrtEdtField('edtNenner_').Visible := false;

CrtLabel('lblQGliederung_');

CrtCombobox('cmbxQGliederungsID_');

CrtEdtField('edtQKnoten01_');

CrtEdtField('edtQKnoten02_');

CrtEdtField('edtQKnoten03_');

CrtEdtField('edtQKnoten04_');

CrtEdtField('edtQKnoten05_');

CrtEdtField('edtQKnoten06_');

CrtEdtField('edtQKnoten07_');



CrtCombobox('cmbxOperator_');



CrtBitBtn('btbtnZRotate_').OnClick := btbtnZRotate_1Click;

CrtLabel('lblZaehler_').Visible := false;

CrtEdtField('edtZaehler_').Visible := false;

CrtLabel('lblZGliederung_').BringToFront;

CrtCombobox('cmbxZGliederungsID_');

CrtEdtField('edtZKnoten01_');

CrtEdtField('edtZKnoten02_');

CrtEdtField('edtZKnoten03_');

CrtEdtField('edtZKnoten04_');

CrtEdtField('edtZKnoten05_');

CrtEdtField('edtZKnoten06_');

CrtEdtField('edtZKnoten07_');



CrtCombobox('cmbxOperatorNext_').OnChange := cmbxOperatorNext_1Change;

end;



end;



Ein TabSheet complett mit seinen Komonenten zu duplizieren wüßte ich nicht wie es gehen soll. Wirst est also denke ich etwa so mache wich ich machen müssen.



Mit ZielObject.Assign(QuelleObject) kannst du die Eigenschaften kopieren (Siehe Hilfe)



Grüße



Thomas






Grüße Thomas

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: