Autor Beitrag
Grafix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Sa 24.04.10 12:57 
Siehe Titel... ist sowas möglich??? Habe ein Form, in der der User Eingaben Treffen kann. Anhand dieser soll die Größe des zweiten Forms, welches mit Form2.Show aufgerufen wird, eben angepasst werden. Ich glaub das Problem ist, dass das Form ja nicht erst erzeugt wird, wenn im ersten Form auf den Button gedrückt wird, sondern sofort beim Programmstart, oder?
Irgendwelche Ideen?
Danke ;)

lg Grafix
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Sa 24.04.10 13:13 
Das is egal wann du es erzeugst, fakt ist, es muss schon erzeugt sein wenn du dir größe ändern willst. ;)

Die größe kannst du einfach mit Form1.Height := 27; und Form1.Width := 27 ändern. Height ändert die Höhe des Formulars und Width die Breite des Formulars. Beide Wollen ein Integer haben. ;)

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Webo
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 577
Erhaltene Danke: 14

Win 7, Debian
C# (Visual Studio 2013), PHP, C, C++ (Eclipse, KDevelop)
BeitragVerfasst: Sa 24.04.10 13:13 
Form2.Width und From2.Height solltest du dir mal anschauen.

Edit: zu langsam :cry:

_________________
Man kann nur das aus dem Ärmel schütteln, was man auch vorher reingesteckt hat.
Grafix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Sa 24.04.10 13:16 
user profile iconelundril hat folgendes geschrieben Zum zitierten Posting springen:
Das is egal wann du es erzeugst, fakt ist, es muss schon erzeugt sein wenn du dir größe ändern willst. ;)


D.H. ich muss die Größe dann Form.Create des selben Forms ändern? Habe es mit den Befehlen Width und Height bereits versucht, allerdings im OnPaint...
Im Form.Create funktioniert es leider auch nicht - habe es auch schon mit ClientWidth versucht - es bleibt immer gleiche Größe...
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Sa 24.04.10 14:44 
Wo rufst du denn das Formular auf? Gleich wenn du das Formular aufrufst davor das hinschreiben, dann sollte es funktionieren.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Grafix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Sa 24.04.10 18:23 
Ich Rufe das Formular von einem Button aus auf. In diese Aktion, vor dem Befehl Form2.Show; habe ich nun Form2.Width := 900; deklariert jedoch immernoch ohne Erfolg?!
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 24.04.10 18:39 
Hi, bist Du sicher das es nur 2 Forms sind! Weil irgendwie nicht nachvollziebar!?
Ansonsten gib mal Code, wo das alles passiert, sonst Raten wir nur!?

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
Grafix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Sa 24.04.10 18:45 
Alles klar, ich poste einfach mal mein ganzes Programm:

Unit 1:
betreffende Zeilen: 128, 129
ausblenden volle Höhe Delphi-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:
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:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
unit UMain;

interface

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

type
  TFMain = class(TForm)
    LTitel: TLabel;
    LWillkommen: TLabel;
    Label1: TLabel;
    CBFeldgrX: TComboBox;
    Label2: TLabel;
    Label3: TLabel;
    CBFeldgrY: TComboBox;
    GBSchiffe_Vorschlag: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    LUBoote: TLabel;
    LKreuzer: TLabel;
    LZerstörer: TLabel;
    LSchlachtschiffe: TLabel;
    BSpielen: TButton;
    procedure FormCreate(Sender: TObject);
    procedure CBFeldgrXChange(Sender: TObject);
    procedure CBFeldgrYChange(Sender: TObject);
    procedure Schiffe_vorschlagen(X, Y: Integer);
    procedure BSpielenClick(Sender: TObject);
  private

  public

  end;

var
  FMain: TFMain;
  X, Y: Integer;
  Spielfertig: Boolean;


implementation

uses UStart;

{$R *.dfm}

procedure TFMain.FormCreate(Sender: TObject);
var
  I, K: Integer;
begin
  for I := 0 to 10 do
    begin
      K := I + 10;
      CBFeldgrX.Items.Add(IntToStr(K));
    end;
  for I := 0 to 10 do
    begin
      K := I + 10;
      CBFeldgrY.Items.Add(IntToStr(K));
    end;

  // Auf -1 setzten für spätere Schiffsauswahl
  X := -1;
  Y := -1;
end;

procedure TFMain.Schiffe_vorschlagen;
begin
  //Schlägt Schiffbelegung aufgrund der gegebenen Koods vor

  GBSchiffe_vorschlag.Visible := True;

  X := X + 10;
  Y := Y + 10;

  if (X * Y < 196then
  // 14 * 14
  begin
    LUBoote.Caption := IntToStr(4);
    LKreuzer.Caption := IntToStr(3);
    LZerstörer.Caption := IntToStr(2);
    LSchlachtschiffe.Caption := IntToStr(1);
  end
  else if (X * Y >= 196and (X * Y < 289then
  // 17 * 17
  begin
    LUBoote.Caption := IntToStr(6);
    LKreuzer.Caption := IntToStr(4);
    LZerstörer.Caption := IntToStr(2);
    LSchlachtschiffe.Caption := IntToStr(1);
  end
  else if (X * Y >= 289and (X * Y < 400then
  // > 17
  begin
    LUBoote.Caption := IntToStr(8);
    LKreuzer.Caption := IntToStr(6);
    LZerstörer.Caption := IntToStr(3);
    LSchlachtschiffe.Caption := IntToStr(1);
  end
  else if (X * Y = 400then
  // 20 * 20
  begin
    LUBoote.Caption := IntToStr(8);
    LKreuzer.Caption := IntToStr(6);
    LZerstörer.Caption := IntToStr(3);
    LSchlachtschiffe.Caption := IntToStr(2);
  end;

  Spielfertig := True;

end;

procedure TFMain.BSpielenClick(Sender: TObject);
var
  ZweiteForm: TFStart;
begin
  if (CBFeldgrX.ItemIndex <> -1and (CBFeldgrY.ItemIndex <> -1then
  begin
    // Übergebe die ausgewählten Argumente
    ZweiteForm := TFStart.Create(nil);
    try
      ZweiteForm.GiveArguments1 := X + 10;
      ZweiteForm.GiveArguments2 := Y + 10;
      FStart.Width := 649 + X * 27 * 2;
      FStart.Height := 900;
      ZweiteForm.ShowModal;
    finally
      ZweiteForm.Free;
    end;
  end;
end;

procedure TFMain.CBFeldgrXChange(Sender: TObject);
begin
  X := CBFeldgrX.ItemIndex;

  if Y > -1 then
    Schiffe_vorschlagen(X, Y);
end;

procedure TFMain.CBFeldgrYChange(Sender: TObject);
begin
  Y := CBFeldgrY.ItemIndex;

  if X > -1 then
    Schiffe_vorschlagen(X, Y);
end;

end.


Unit 2:
ausblenden volle Höhe Delphi-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:
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:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
unit UStart;

interface

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

type
  TFStart = class(TForm)
    Label3: TLabel;
    GBPlayer1: TGroupBox;
    GBPlayer2: TGroupBox;
    BeispielPanel: TPanel;
    GBSchiffe_setzten: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    LAnzahlUBoote: TLabel;
    LAnzahlKreuzer: TLabel;
    LKreuzer: TLabel;
    LAnzahlZerstörer: TLabel;
    LZerstörer: TLabel;
    LAnzahlSchlachtschiffe: TLabel;
    LSchlachtschiffe: TLabel;
    Label6: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure BeispielPanelMouseLeave(Sender: TObject);
    procedure PanelXMouseEnter(Sender: TObject);
    procedure PanelXMouseLeave(Sender: TObject);
    procedure BeispielPanelMouseEnter(Sender: TObject);
  private
    { Private-Deklarationen }
    FGiveArguments1: Integer;
    FGiveArguments2: Integer;
  public
    { Public-Deklarationen }
    property GiveArguments1: Integer read FGiveArguments1 write FGiveArguments1;
    property GiveArguments2: Integer read FGiveArguments2 write FGiveArguments2;
  end;

var
  FStart: TFStart;

implementation

uses UMain;

{$R *.dfm}

procedure TFStart.BeispielPanelMouseEnter(Sender: TObject);
begin
  BeispielPanel.Color:= clRed;
end;

procedure TFStart.BeispielPanelMouseLeave(Sender: TObject);
begin
  BeispielPanel.Color := clBtnFace;
end;

procedure TFStart.PanelXMouseEnter(Sender: TObject);
begin
  if (Sender is TPanel) then
  begin
    TPanel(Sender).Color := clRed;
    //ShowMessage(IntToStr(TPanel(Sender).Tag));
  end;
end;

procedure TFStart.PanelXMouseLeave(Sender: TObject);
begin
  if (Sender is TPanel) then
  begin
    TPanel(Sender).Color := clBlue;
  end;
end;

procedure TFStart.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FMain.Close;
end;

procedure TFStart.FormCreate(Sender: TObject);
begin
  GBPlayer1.Width := 300 + X * 27;
  GBPlayer1.Height := 310 + Y * 27;
  GBPlayer2.Width := 300 + X * 27;
  GBPlayer2.Height := 310 + Y * 27;
  GBPlayer2.Left := 314 + X * 27;
  GBSchiffe_setzten.Left := 346 + X * 27;
end;

procedure TFStart.FormShow(Sender: TObject);
var
  I: Integer;
  MyPanel: TPanel;
  K: Integer;
  AnzahlUBoote, AnzahlKreuzer, AnzahlZerstörer, AnzahlSchlachtschiffe: Integer;
  Pfad: String;
begin
  // FMain Schließen / unsichtbar machen
  // FMain.Hide;

  X := FGiveArguments1;
  Y := FGiveArguments2;

  // Schiffbelegung
  // Bis 14x14
  if (X * Y < 196then
  begin
    AnzahlUBoote := 4;
    AnzahlKreuzer := 3;
    AnzahlZerstörer := 2;
    AnzahlSchlachtschiffe := 1;
  end
  // Bis 17x17
  else if (X * Y >= 196and (X * Y < 289then
  begin
    AnzahlUBoote := 6;
    AnzahlKreuzer := 4;
    AnzahlZerstörer := 2;
    AnzahlSchlachtschiffe := 1;
  end
  // Bis 19x20
  else if (X * Y >= 289and (X * Y < 400then
  begin
    AnzahlUBoote := 8;
    AnzahlKreuzer := 6;
    AnzahlZerstörer := 3;
    AnzahlSchlachtschiffe := 1;
  end
  // Bei 20x20
  else if (X * Y = 400then
  begin
    AnzahlUBoote := 8;
    AnzahlKreuzer := 6;
    AnzahlZerstörer := 3;
    AnzahlSchlachtschiffe := 2;
  end;

  // Spielfeldraster erstellen
  for K := 1 to Y do
  begin
    for I := 1 to X do
    begin
      Pfad := IntToStr(I + (K * X) - X);

      MyPanel := TPanel.Create(Self);
      MyPanel.Parent := GBPlayer1;
      MyPanel.Name := 'Panel' + Pfad + 'Player1';
      MyPanel.Caption := Pfad;
      MyPanel.Left := 14 + (I - 1) * 27;
      MyPanel.Top := 24 + (K - 1) * 27;
      MyPanel.Width := 25;
      MyPanel.Height := 25;
      //MyPanel.Tag := I * K;
      MyPanel.OnMouseEnter := PanelXMouseEnter;
      MyPanel.OnMouseLeave := PanelXMouseLeave;
    end;
  end;

  // Spielfeld von Player2 ausblenden
  GBPlayer2.Visible := False;

  // GBSchiffe_setzten einblenden und auswahl starten
  GBSchiffe_setzten.Visible := True;
  LAnzahlUBoote.Caption := IntToStr(AnzahlUBoote);

  // Wenn alle UBoote gesetzt, dann Kreuzer setzten
  LAnzahlKreuzer.Visible := True;
  LKreuzer.Visible := True;
  LAnzahlKreuzer.Caption := IntToStr(AnzahlKreuzer);

  // Wenn alle Kreuzer gesetzt, dann Zerstörer
  LAnzahlZerstörer.Visible := True;
  LZerstörer.Visible := True;
  LAnzahlZerstörer.Caption := IntToStr(AnzahlZerstörer);

  // Wenn alle Zerstörer gesetzt, dann Schlachtschiffe
  LAnzahlSchlachtschiffe.Visible := True;
  LSchlachtschiffe.Visible := True;
  LAnzahlSchlachtschiffe.Caption := IntToStr(AnzahlSchlachtschiffe);

end;

end.


Da ich das hier gerade schon mal alles Gepostet habe, könntet ihr auch nochmal bitte einen Blick auf Zeile 149f werfen? Da ja offensichtlich zweimal die Variable Pfad verwendet wird, müsste ja auch zweimal das gleiche Ergebnis rauskommen - tut es aber nicht.
Bei MyPanel.Caption stimmts, bei MyPanel.Name nicht?!?! *verwirrung*
Vielen vielen Dank!!!
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 24.04.10 19:15 
Ist es dieses was nicht funct?
ausblenden Delphi-Quelltext
1:
2:
FStart.Width := 649 + X * 27 * 2;
FStart.Height := 900;

ändere mal um in
ausblenden Delphi-Quelltext
1:
2:
ZweiteForm.Width := 649 + X * 27 * 2;
ZweiteForm.Height := 900;

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
Grafix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Sa 24.04.10 19:17 
funktioniert - das war die Lösung. Danke schön!

Hat vll noch jemand was zu dem "Pfad"-Problem? *g*
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 24.04.10 19:23 
user profile iconGrafix hat folgendes geschrieben Zum zitierten Posting springen:
Hat vll noch jemand was zu dem "Pfad"-Problem? *g*

Sei jetzt nicht sauer, ein neuer thread wäre schön, nicht weil ich nicht will, sondern es kann ja auch ein andere so ein Problem haben!
Bitte mit der StringAnzeige was da unterschiedlich ist!

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Sa 24.04.10 19:26 
user profile iconALF hat folgendes geschrieben Zum zitierten Posting springen:
Sei jetzt nicht sauer, ein neuer thread wäre schön, nicht weil ich nicht will, sondern es kann ja auch ein andere so ein Problem haben!
Bitte mit der StringAnzeige was da unterschiedlich ist!

Gruss Alf


meinst du vielleicht einen neuen thread wie diesen hier? :mrgreen:

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 24.04.10 19:36 
Jo, da ging es ja um die Farbe 8)
Hier um Form.Heigt und .Width
Seine 2.Frage um Objekt.Name und Objekt.Caption :wink:

Währe ein neuer Thread wert :gruebel:

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
Grafix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Sa 24.04.10 21:25 
Hehe ich bin nicht sauer, ich bins schon gewöhnt darauf aufmerksam gemacht zu werden, zu jedem Problem ein neuen Thread aufzumachen ;) Kommt nicht wieder vor =)

Damit kann dieser hier wohl geschlossen werden, Ursprungsproblem ist ja perfekt gelöst worden!