| Autor |
Beitrag |
Kaihnplahn
Hält's aus hier
Beiträge: 8
|
Verfasst: Mo 25.07.05 20:13
Da das gerade eben so schnell und gut geklappt hat frag ich jetzt noch was:
ich hab ein zweites Form erstellt: TForm2
Jetzt will ich, dass wenn ich dieses Form2 schliesse bei Form1 ereignisse ausgelöst werden:
So ungefähr:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9:
| procedure TForm2.Form2Close(Sender: TObject); begin Showmessage('You found:'+#13 +'3 Health Potions'+#13 +'4 Mana Potions'+#13 +'1 shield'); Form1.Healthp.Text := IntToStr(StrToInt(Form1.Healthp.Text) + 3); Form1.Magicp.Text := IntToStr(StrToInt(Form1.Magicp.Text) + 4); end; |
Den Code hab ich bei unit2 eingegeben. Aber es passiert nichts!!!
Was hab ich falsch gemacht. Der startet zwar das programm also sind keine "richtigen" Fehler drin aber er führt beim schliessen nichts aus.
bitte helft mit am besten wieder so schnell wie bei meiner anderen Frage.
3Min sind zu toppen!!!
MFG
Moderiert von Gausi: Delphi-Tags hinzugefügt.Moderiert von Gausi: Topic aus CLX / Delphi Language (Object-Pascal) verschoben am Di 26.07.2005 um 08:53
|
|
maxk
      
Beiträge: 1696
Erhaltene Danke: 1
Win XP, Debian Lenny
Delphi 6 Personal
|
Verfasst: Mo 25.07.05 20:39
Dann musst du noch vor dem Öffnen (falls du mit ShowModal) arbeitest. Den Zeiger auf die Methode setzen: Delphi-Quelltext 1:
| Form2.OnClose:=Form2Close; | Damit sollte es gehen  Wenn nicht, poste bitte noch etwas Code, sonst wird das auch in 30 Minuten nichts
Gruß,
maxk
// Edit: Das Schieben ist hier generell unerwünscht. Und wenn du schon nach etwa 20 Minuten schiebst, ist das mehr als frech 
_________________ Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
|
|
Kaihnplahn 
Hält's aus hier
Beiträge: 8
|
Verfasst: Mo 25.07.05 20:52
Titel: Ups
Tut mir leid wenn ich hier voll die anfänger fragen stell aber ... DAS GEHT NICHT...
Also 1. weiss ich nciht wo ich dieses ereignis einfügen soll...
Als ich es in das gleich procedure eingebaut habe ging gar nichts mehr...
Also mal noch ein bisschen mehr code. Was wollt ihr denn noch sehen?
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: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311:
| unit Unit2;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, jpeg;
type TForm2 = class(TForm) Image1: TImage; Image2: TImage; Image3: TImage; Image4: TImage; Image5: TImage; Attack1: TButton; HP1: TEdit; MP1: TEdit; HP2: TEdit; MP2: TEdit; HP3: TEdit; MP3: TEdit; Attack2: TButton; Attack3: TButton; HPself: TEdit; MPself: TEdit; APself: TEdit; AP1: TEdit; AP2: TEdit; AP3: TEdit; Start: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; AMself: TEdit; AM1: TEdit; Am2: TEdit; Am3: TEdit; Round: TButton; Image6: TImage; ListBox1: TListBox; Image7: TImage; Roundnr: TEdit; Label4: TLabel; Image8: TImage; Image9: TImage; Image10: TImage; Image11: TImage; procedure StartClick(Sender: TObject); procedure Attack1Click(Sender: TObject); procedure Attack2Click(Sender: TObject); procedure Attack3Click(Sender: TObject); procedure RoundClick(Sender: TObject); procedure Image6Click(Sender: TObject); procedure Image7Click(Sender: TObject); procedure Image8Click(Sender: TObject); procedure Image9Click(Sender: TObject); procedure Image10Click(Sender: TObject); procedure Form2Close(Sender: TObject); private public end;
var Form2: TForm2;
implementation
uses HeroEditor1;
{$R *.dfm}
procedure TForm2.StartClick(Sender: TObject); var index1: integer; index7: integer; begin index1 := Form1.ComboBox1.ItemIndex; index7 := Form1.ComboBox7.ItemIndex; Start.Enabled := False; Label1.Caption := 'Reegal'; Label2.Caption := 'Reegal'; Label3.Caption := 'Reegal'; HPself.Text := Form1.HPleft.Text; MPself.Text := Form1.MPleft.Text; APself.Text := Form1.APleft.Text; AMself.Text := Form1.Armor.Text; Form2.Image2.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Reegal.jpg'); Form2.Image3.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Reegal.jpg'); Form2.Image4.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Reegal.jpg'); Form2.Image1.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Hintergrund\Mysticland.jpg'); HP1.Text := ('115'); HP2.Text := ('115'); HP3.Text := ('115'); MP1.Text := ('0'); MP2.Text := ('0'); MP3.Text := ('0'); AP1.Text := ('20'); AP2.Text := ('20'); AP3.Text := ('20'); AM1.Text := ('5'); AM2.Text := ('5'); AM3.Text := ('5'); if index1 = 0 then begin Form2.Image5.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Malekampf.jpg'); end; if index1 = 1 then begin Form2.Image5.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Femalekampf.jpg'); end; if index7 = 3 then begin Form2.Image9.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Zauber\Protection.jpg'); end; if index7 = 4 then begin Form2.Image8.Picture.LoadFromFile('F:\Eigene Dateien\Delphi\Helden\Zauber\Fireattack.jpg'); end; end;
procedure TForm2.Attack1Click(Sender: TObject); begin HP1.Text := IntToStr(StrToInt(HP1.Text) - StrToInt(APself.Text) + StrToInt(AM1.Text)); Attack1.Enabled := false; Attack2.Enabled := false; Attack3.Enabled := false; end;
procedure TForm2.Attack2Click(Sender: TObject); begin HP2.Text := IntToStr(StrToInt(HP2.Text) - StrToInt(APself.Text) + StrToInt(AM1.Text)); Attack1.Enabled := false; Attack2.Enabled := false; Attack3.Enabled := false; end;
procedure TForm2.Attack3Click(Sender: TObject); begin HP3.Text := IntToStr(StrToInt(HP3.Text) - StrToInt(APself.Text) + StrToInt(AM1.Text)); Attack1.Enabled := false; Attack2.Enabled := false; Attack3.Enabled := false; end;
procedure TForm2.RoundClick(Sender: TObject);
begin Roundnr.Text := IntToStr(StrToInt(Roundnr.Text) + 1); Image6.Enabled := true; Image7.Enabled := true; If StrToInt(HP1.Text) < 1 then begin AP1.Text := ('0'); HP1.Text := ('0'); end;
If StrToInt(HP2.Text) < 1 then begin AP2.Text := ('0'); HP2.Text := ('0'); end;
If StrToInt(HP3.Text) < 1 then begin AP3.Text := ('0'); HP3.Text := ('0'); end; begin HPself.Text := IntToStr(StrToInt(Hpself.Text) - StrToInt(AP1.Text) - StrToInt(AP2.Text) - StrToInt(AP3.Text) + StrToInt(AMself.Text)); if StrToInt(HP1.Text) > 0 then begin Attack1.Enabled := true; end; if StrToInt(HP2.Text) > 0 then begin Attack2.Enabled := true; end; if StrToInt(HP3.Text) > 0 then begin Attack3.Enabled := true; end;
if StrToInt(HPself.Text) < 1 then begin showmessage('You have been defeated'+#13 +'You will now loose all your gold but return with full health'+#13 +'Please close this window to continue'); HPself.Text := ('0'); APself.Text := ('0'); MPself.Text := ('0'); Attack1.Enabled := false; Attack2.Enabled := false; Attack3.Enabled := false; ListBox1.Enabled := false; Round.Enabled := false; end; if StrToInt(HP1.Text + HP2.Text + HP3.Text) = 0 then begin showmessage('Congratulations You have WON'+#13 +'You can heal yourself once more'+#13 +'remember you can not cast spells outside combat'+#13 +'To continue please close this window'); Attack1.Enabled := false; Attack2.Enabled := false; Attack3.Enabled := false; ListBox1.Enabled := false; Round.Enabled := false; end;
end; end;
procedure TForm2.Image6Click(Sender: TObject); var spell: integer; begin spell := Listbox1.ItemIndex; if StrToInt(MPself.Text) >= 10 then begin if spell = 0 then begin MPself.Text := IntToStr(StrToInt(MPself.Text) - 10); Hp1.Text := IntToStr(StrToInt(HP1.Text) - (StrToInt(Form1.FDarkSide.Text) * 3)); end; if spell = 1 then begin MPself.Text := IntToStr(StrToInt(MPself.Text) - 10); Hp2.Text := IntToStr(StrToInt(HP2.Text) - (StrToInt(Form1.FDarkSide.Text) * 3)); end; if spell = 2 then begin MPself.Text := IntToStr(StrToInt(MPself.Text) - 10); Hp3.Text := IntToStr(StrToInt(HP3.Text) - (StrToInt(Form1.FDarkSide.Text) * 3)); end;
Image6.Enabled := false; end; end;
procedure TForm2.Image7Click(Sender: TObject); begin if StrToInt(Mpself.Text) >= 10 then if StrToInt(HPself.Text) + StrToInt(Form1.FGoodSide.Text) * 3 > StrToInt(Form1.HPleft.Text) then begin HPself.Text := Form1.HPleft.Text; end else begin HPself.Text := IntToStr(StrToInt(HPself.Text) + (StrToInt(Form1.FGoodSide.Text) * 3)) end; Image7.Enabled := false; end;
procedure TForm2.Image8Click(Sender: TObject); begin if StrToInt(MPself.Text) >= 50 then Mpself.Text := IntToStr(StrToInt(MPself.text) - 50); HP1.Text := IntToStr(StrToInt(HP1.Text) - StrToInt(Form1.FDarkSide.Text) * 2); HP2.Text := IntToStr(StrToInt(HP2.Text) - StrToInt(Form1.FDarkSide.Text) * 2); HP3.Text := IntToStr(StrToInt(HP3.Text) - StrToInt(Form1.FDarkSide.Text) * 2); end;
procedure TForm2.Image9Click(Sender: TObject); begin if StrToInt(MPself.Text) >= 50 then begin MPself.Text := IntToStr(StrToInt(MPself.Text) - 50); AMself.Text := IntToStr(StrToInt(AMself.Text) + StrToInt(Form1.FGoodside.Text) * 2); Image9.Enabled := false; end; end;
procedure TForm2.Image10Click(Sender: TObject); begin if StrToInt(Form1.healthp.Text) > 0 then begin Form1.healthp.Text := IntToStr(StrToInt(Form1.healthp.Text) - 1); if StrToInt(HPself.Text) + 50 > StrToint(Form1.HPright.Text) then begin HPself.Text := IntToStr(StrToInt(HPself.Text) + 50); end; end; end;
procedure TForm2.Form2Close(Sender: TObject); begin Showmessage('You found:'+#13 +'16 Gold'+#13 +'3 Health Potions'+#13 +'4 Mana Potions'+#13 +'level 1 shield'); Form1.Healthp.Text := IntToStr(StrToInt(Form1.Healthp.Text) + 3); Form1.Magicp.Text := IntToStr(StrToInt(Form1.Magicp.Text) + 4); Form1.Gold.Text := IntToStr(StrToInt(Form1.gold.Text) + 16); Form1.ComboBox9.Items.Add('1. Wooden shield (Armor + 5, MP + 5)'); Form1.ComboBox9.Items.Add('2. Leather shield (HP + 15)'); Form1.ComboBox9.Items.Add('3. Steel shield (Armor + 10)'); end;
end. |
So ich glaub das reicht dann mal.
Das ist nur der Code für Form2 wenn ihr den für Form1 auch braucht dann macht euch ma auf etwa 40-60 seiten gefasst...
BITTE helft mir...
MFG
Zuletzt bearbeitet von Kaihnplahn am Mo 25.07.05 20:56, insgesamt 1-mal bearbeitet
|
|
Tobias1
      
Beiträge: 454
Win 98, XP Prof
D3 Prof, D2005 Prof
|
Verfasst: Mo 25.07.05 20:55
Oh.. mach mal Delphi-Tags drum [delphi] [/delphi ]
_________________ Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
|
|
maxk
      
Beiträge: 1696
Erhaltene Danke: 1
Win XP, Debian Lenny
Delphi 6 Personal
|
Verfasst: Mo 25.07.05 21:05
Was ich meinte: Klick mal auf dein 2. Formular und überprüfe, ob bei den Ereignissen bei OnClose die richtige Methode eingetragen ist. Wenn nicht, eintragen. Wenn es dann immernoch nicht funktioniert, melde dich nochmal. Dann scheint was faul 
_________________ Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
|
|
Kaihnplahn 
Hält's aus hier
Beiträge: 8
|
Verfasst: Mo 25.07.05 21:09
Tut mir echt leid wegen 2 Dingen:
1. Das mit dem Verschieben... ich hab mich selber schwer gewundert dass mein post plötzlich weg war hab aber dann gesehen dass er in ein anderes Topic verschoben wurde. Also das war ich bestimmt nicht.
2. Ich blicks immer noch nicht...
Also was meinst du denn mit der richtigen Methoode???
Meinst du bei Type??? da Hab ich
procedure Form2Close(Sender: TObject);
eingegeben.
Danke für eure Geduld und
BITTTE helft mir
MFG
|
|
maxk
      
Beiträge: 1696
Erhaltene Danke: 1
Win XP, Debian Lenny
Delphi 6 Personal
|
Verfasst: Mo 25.07.05 21:22
Es reicht nicht aus eine Methode zu schreiben, du musst Delphi auch mitteilen, wann sie gebraucht werden (oder od du sie nur intern benutzt). Dazu klickst du zur Entwurfszeit eine freie Stelle auf deinem Form2 an und wählst dann im Objektinspektor den Reiter "Ereignisse" bzw. "Events". Dort suchst du OnClose raus und klickst es einmal an. Daneben befindet sich nun eine kleine Auswahlliste, ausder du deine Methode auswählst "Form2Close" und anschließend Enter drückst. Damit weiss Delphi, was wann zu tun ist. Wenn dort bereits der richtige Wert drinsteht, ist das eine Sackgasse. Ansonsten liegt es daran.
Gruß,
maxk
_________________ Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
|
|
Kaihnplahn 
Hält's aus hier
Beiträge: 8
|
Verfasst: Di 26.07.05 18:01
ääääääääääääääääääääääääääääh
also ich weiss nciht ob ich was falsch gemacht habe aber...
als ich form2 ausgewählt habe, da konnte mann bei onclose nichts aussuchen.
Form2.Close und Form2CLose haben auhc nicht funktioniert als ichs eingegebn habe.
Bitte helft mir noch einmal...
MFG
|
|
maxk
      
Beiträge: 1696
Erhaltene Danke: 1
Win XP, Debian Lenny
Delphi 6 Personal
|
Verfasst: Di 26.07.05 18:55
Jetzt sehe ich es auch! Deine Methode ist von Typ TNotifyEvent, was mit OnClose/OnCanClose nicht funktioniert. Den Code deiner Methode ausschneiden und die gesamte Methode entfernen. Dann Doppelklick auf das weiße Feld, wo du was eingeben solltest und in das Codefenster an dieser Stelle wieder den vorherigen Code einfügen.
Gruß,
maxk
_________________ Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
|
|