Hallo
Ich möchte belibig viele Componenten zur Laufzeit erschaffen können. Dazu habe ich folgendes Programm geschrieben.
Man benötigt:
Eine Form mit dem Namen Felder_Form
Ein PageControle mit dem Namen Felder_Controle
Einen Button mit dem Namen Erschaffen_Button.
Alles andere sollte sich aufgrund des Codes erschaffen lassen
Das Programm:
Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| program felder;
uses Forms, erzeugen in 'erzeugen.pas' {felder_form};
{$R *.RES}
begin Application.Initialize; Application.CreateForm(Tfelder_form, felder_form); Application.Run; end. |
Die Unit:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96:
| unit erzeugen;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls;
type Tfelder_form = class(TForm) felder_controle: TPageControl; erschaffen_button: TButton; procedure FormResize(Sender: TObject); procedure erschaffen_buttonClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private-Deklarationen } public boden_feld:ARRAY OF TTabSheet; eingabe_feld: ARRAY OF TEdit; anzeige_feld: ARRAY OF TRichEdit; nick_feld : Array OF TMemo; trennen_feld_button: ARRAY OF TButton; { Public-Deklarationen } end;
var felder_form: Tfelder_form;
implementation
{$R *.DFM}
procedure Tfelder_form.FormResize(Sender: TObject); begin felder_controle.Height := felder_form.ClientHeight - erschaffen_button.Height - 5; felder_controle.Width := felder_form.ClientWidth; erschaffen_button.Top := felder_controle.Height + 2; erschaffen_button.Left :=0; end;
procedure Tfelder_form.erschaffen_buttonClick(Sender: TObject); VAR index,index2:INTEGER; begin index := Length(boden_feld); index2:=index; SetLength(boden_feld,index + 1); boden_feld[index2] := TTabSheet.Create(felder_controle); boden_feld[index2].PageControl :=felder_controle; boden_feld[index2].caption := IntToStr(index); boden_feld[index2].left:=0; boden_feld[index2].top :=0; boden_feld[index2].width := felder_controle.ClientWidth; boden_feld[index2].height := felder_controle.ClientHeight; boden_feld[index2].show; boden_feld[index2].setfocus; SetLength(anzeige_feld,index + 1); anzeige_feld[index2] :=TRichEdit.Create(boden_feld[index2]); anzeige_feld[index2].left:=0; anzeige_feld[index2].top :=0; anzeige_feld[index2].width := boden_feld[index2].ClientWidth - 100; anzeige_feld[index2].height := boden_feld[index2].ClientHeight - 52; anzeige_feld[index2].show; SetLength(eingabe_feld,index + 1); eingabe_feld[index2] := TEdit.Create(boden_feld[index2]); eingabe_feld[index2].left := 0; eingabe_feld[index2].top := anzeige_feld[index2].height + 2; eingabe_feld[index2].width := boden_feld[index2].ClientWidth - 100; eingabe_feld[index2].height := 50; eingabe_feld[index2].show;
SetLength(nick_feld,index + 1); nick_feld[index2] := TMemo.Create(boden_feld[index]);
SetLength(trennen_feld_button,index + 1); trennen_feld_button[index2] := TButton.Create(boden_feld[index]);
end;
procedure Tfelder_form.FormClose(Sender: TObject; var Action: TCloseAction); VAR index:INTEGER; begin For index := 0 to High(eingabe_feld) DO eingabe_feld[index].Free; For index := 0 to High(anzeige_feld) DO anzeige_feld[index].free; For index := 0 to High(nick_feld) DO nick_feld[index].free; For index := 0 to High(trennen_feld_button) DO trennen_feld_button[index].free; For index := 0 to High(boden_feld) DO boden_feld[index].free; end;
end. |
So, nun zum eigentlichen Problem. Es werden zwar TTabSheet's erschaffen, aber darauf erscheint weder das TRichEdit noch das TEdit obwohl ich sie erschaffe, eine Position zuweise und Show auslöse. Was mache ich falsch????????
cu Patmann