Autor |
Beitrag |
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Di 21.04.15 17:33
ne dazu hab ich echt gar keine idee o.O
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 21.04.15 17:58
Moin!
Nini hat folgendes geschrieben : | ne dazu hab ich echt gar keine idee o.O |
Hm, das ist aber potenziell ganz schlecht, weil wer soll das dann machen... ?
So schwer ist das gar nicht, nur etwas viel. Du kennst doch arrays, haben wir doch schon benutzt. Hilft uns sowas vielleicht weiter?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Di 21.04.15 18:19
vielleicht kann man die shapes als feld übergeben? also wieder zweidimensional oder so? :/
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 21.04.15 18:38
Moin!
Ja, das ist eine Möglichkeit. Einfach noch ein Feld (2-dimensionales Array) für die Shapes anlegen, so wie bei den Booleans für die Berechnung. Dann mach mal einen Vorschlag, wie das aussehen könnte (ist egal wenn das falsch ist, Rom wurde auch nicht an einem Tag erbaut ).
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Mi 22.04.15 17:14
ich bin mir noch ganz unsicher, wie ich was da machen muss ...
als erstes glaub ich muss ich das feld deklarieren, bestimmt am besten unter public, dass es global ist aber welcher klasse soll ich das neue feld zuweisen?
geht das so? Delphi-Quelltext 1: 2: 3: 4: 5:
| type TFeldShape = array[0..N-1, 0..N-1] of TShape; [...] public FeldShape : TFeldShape; |
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 22.04.15 21:10
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Mi 22.04.15 21:26
dann mein ich bestimmt elementtyp, ich komm mit den ganzen begriffen nicht so ganz klar
Delphi-Quelltext 1: 2: 3: 4: 5:
| type TFeldShape = array[0..30, 0..30] of TShape; [...] public FeldShape : TFeldShape; |
ich kann ja so einfach einen höchstwert für die Feldgröße festlegen
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 22.04.15 21:58
Moin!
Nini hat folgendes geschrieben : | dann mein ich bestimmt elementtyp, ich komm mit den ganzen begriffen nicht so ganz klar |
Alles OK.
Nini hat folgendes geschrieben : | ich kann ja so einfach einen höchstwert für die Feldgröße festlegen |
Perfekt! Genau so, einfach einen Maximalwert festlegen. Aaaaber... dann bitte auch als Konstante wie N deklarieren (z.B. als "Nmax"). Wie würde das dann aussehen?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Mi 22.04.15 22:47
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8:
| const Nmax = 35; [...] type TFeldShape = array[0..NMax-1, 0..NMAX-1] of TShape; [...] public FeldShape : TFeldShape; |
wäre das dann so?
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 22.04.15 23:20
Moin!
Top!
Dann müssen wir jetzt als nächstes die Shape-Erzeugung angehen: die müssen jetzt mit "nil" als Parameter erzeugt werden und dann als Referenz im neuen Feld abgelegt werden.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Do 23.04.15 18:26
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| procedure TForm1.FormCreate(Sender: TObject); var snr,y,x : integer; shape : TShape; begin for y := 0 to N-1 do for x := 0 to N-1 do begin Shape := TShape.Create(Nil); Shape.Parent := Self; snr := x +y *N +1; Shape.Name := 'Shape'+inttostr(snr); Shape.Left := 10+x*25; Shape.Top := 80+y*25; Shape.Width := 25; Shape.Height := 25; Shape.OnMouseDown := @Shape1MouseDown; FeldShape[x,y] := Shape; end; ClientHeight := N*25+100; ClientWidth := N*25+20; end; |
Ist das dann irgendwie so in der Art?
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Do 23.04.15 18:36
Moin!
Nini hat folgendes geschrieben : | Ist das dann irgendwie so in der Art? |
Sollte passen.
Dann brauchen wir noch einen Schieberegler oben im Formular, welcher zwischen 3 und Nmax einstellbare Werte erlaubt (weniger als 3 macht keinen Sinn und mehr als Nmax erlauben wir nicht).
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Do 23.04.15 18:54
hab ich eingebaut
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Fr 24.04.15 12:34
Moin!
Nini hat folgendes geschrieben : | hab ich eingebaut |
Fein. Hast du das denn auch so gemacht, dass man nur die Konstante Nmax ändern muss, wenn man diesen Wert verändern möchte?
Als nächstes müssen wir uns darum kümmern, dass die erstellen Shapes, die ja nun uns gehören, auch beim Programmende wieder freigegeben werden. Sonst haben wir ein Speicher-Leck (wir fordern Speicher für die Shapes an, aber geben ihn nicht wieder frei )! Dazu eine Idee?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Fr 24.04.15 19:36
Ne der wollte NMax als maximumwert nicht akzeptieren :/
Nee da hab ich leider keine idee
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Fr 24.04.15 20:28
Moin!
Nini hat folgendes geschrieben : | Ne der wollte NMax als maximumwert nicht akzeptieren :/ |
Ja, das hab ich mir schon gedacht. Lösung: In der FormCreate-Methode musst du den Maximalwert per Code setzen.
Nini hat folgendes geschrieben : | Nee da hab ich leider keine idee |
Was sich auf das Freigeben bezieht, nehme ich an. Ansatz: Du läufst mit einer Schleife über alle Felder in FeldShape und wenn da nicht Nil drin steht, dann gibst du das Element mit .Free; frei und setzt dann das Element auf Nil. Das Ganze könnte z.B. im FormDestroy passieren...
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Fr 24.04.15 21:57
was ist denn formdestroy? o.O
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Fr 24.04.15 22:01
Moin!
Das ist die Methode, die aufgerufen wird, wenn das Formular gelöscht werden soll. Zumindest bei Delphi kommt man da so dran: das Formular markieren, dann im Objekt-Inspektor auf die Ereignisse-Seite wechseln, in der Liste dann einen Doppelklick auf OnDestroy machen, dann wird der Handler erzeugt.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: Fr 24.04.15 23:07
danke, hab es jetzt gefunden
aber ich glaube ich hab das was ich machen soll nicht ganz verstanden, ich wür es so machen aber dass sieht falsch aus Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| procedure TForm1.FormDestroy(Sender: TObject); var y,x : integer;
begin for y := 0 to N-1 do for x := 0 to N-1 do begin if not FeldShape(nil) then FeldShape.free; FeldShape.free := FeldShape.nil; end; end; |
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Fr 24.04.15 23:39
Moin!
Nini hat folgendes geschrieben : | aber ich glaube ich hab das was ich machen soll nicht ganz verstanden |
Ja, das könnte sein. Ist aber nicht schlimm, das kriegen wir hin.
Dann fangen wir mal an: - Wie greift man auf eine Feldvariable zu (=array-element)? Mit eckigen Klammern!
- Du verwendest x und y als Schleifenvariablen, aber nutzt sie nirgendwo
- Man kann ganz simpel prüfen, ob eine Variable nil ist, einfach mit: if (variable = nil) then
- Man kann nil einer Variablen auch ganz genau so einfach zuweisen: variable := nil;
Damit solltest du erstmal weiter kommen.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|