Autor Beitrag
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mi 05.03.03 22:24 
Ich benutze den folgenden Code zum Erstellen einer neuen Form. Dies soll bei jedem Klick auf den Button geschehen und jede neue Form soll etwas nach Rechts-unten verschoben werden.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
if New = 1 then
    begin
      FNew[Count] := TFNew.Create(FMain);
      FNew[Count].Show;
      FNew[Count].Caption := 'FNew[' + IntToStr(count) + ']';
      posx := FNew[Count].Left;
      posy := FNew[Count].Top;
      Inc(count);
      Inc(New);
    end
  else
    begin
      FNew[Count] := TFNew.Create(FMain);
      FNew[Count].Caption := 'FNew[' + IntToStr(count) + ']';
      posx := posx + 20;
      posy := posy + 30;
      SetWindowPos(FNew[count].Handle, HWND_TOP, posx, posy, FNew[count].Width, FNew[count].Height, SWP_SHOWWINDOW);
      ShowWindow(FNew[count].Handle, SW_SHOWNORMAL);
      Inc(count);
      Inc(New);
    end;


Zur Erklärung count ist vom Typ Byte, New ist vom Typ Byte, FNew ist ein array [0..255] von TFNew und posx, posy werden zum Verschieben benötigt. New wird bei Form1.FormCreate auf 1 und count auf 0 gesetzt.

Jetzt das Problem:
Wenn ich auf den Button klicke wird die erste Form angezeigt. auch die Caption stimmt. Wenn ich jetzt noch mehrmals draufklicke erscheinen zwar neue Formen, die auch richtig durchgezählt sind, aber das Memo, das drauf sein sollte ist nicht mehr da und ich kann die neu erstellten Fenster nur noch über Strg+F2 loswerden.

Weis jemand, wo der Fehler ist?

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Spike
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 69
Erhaltene Danke: 1



BeitragVerfasst: Mi 05.03.03 23:24 
Hi derDoc,

hab den Fehler in Deinem Text auch nicht gefunden. Aber ich würde das ganze auch komplett anders lösen:
ausblenden Quelltext
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:
procedure TForm1.Button1Click(Sender: TObject);
var
  count,x,y : Integer;
  Memo : TMemo;
begin
  count := Length(New);
  Setlength(New, count+1);
  New[Count] := TForm.Create(SELF);
  With New[Count] do begin
    BorderStyle := bsSingle;
    if Count > 0 then begin
      x := New[Count-1].Left + 20;
      y := New[Count-1].Top + 20;
    end else begin
      x := 0; y := 0;
    end;
    SetBounds(x,y,250,150);
    Caption := 'New '+ IntToStr(count);
    Show;
  end;

  Memo := TMemo.Create(New[count]);
  With Memo do begin
    Parent := New[Count];
    SetBounds(0,0,100,100);
    Show;
  end;
end;


Dann brauchst du nur noch New als Array of TForm deklarieren und fertig.