Autor Beitrag
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Di 21.04.15 17:33 
ne dazu hab ich echt gar keine idee o.O
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 21.04.15 17:58 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
ne dazu hab ich echt gar keine idee o.O
Hm, das ist aber potenziell ganz schlecht, weil 8) wer soll das dann machen... ? :lupe: :P

So schwer ist das gar nicht, nur etwas viel. :? Du kennst doch arrays, haben wir doch schon benutzt. Hilft uns sowas vielleicht weiter? :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Di 21.04.15 18:19 
vielleicht kann man die shapes als feld übergeben? also wieder zweidimensional oder so? :/
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: 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. :idea: Dann mach mal einen Vorschlag, wie das aussehen könnte (ist egal wenn das falsch ist, Rom wurde auch nicht an einem Tag erbaut :P). :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: 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?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
type
TFeldShape = array[0..N-10..N-1of TShape; 
[...]
 public
    FeldShape : TFeldShape;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 22.04.15 21:10 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
ich bin mir noch ganz unsicher, wie ich was da machen muss ...
Das wird schon. :zustimm:

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
als erstes glaub ich muss ich das feld deklarieren,
Jup.

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
bestimmt am besten unter public, dass es global ist
Ist OK.

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
aber welcher klasse soll ich das neue feld zuweisen?
Hä? :gruebel: Meinst du den Elementtyp, da ist doch TShape genau richtig. ;)

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
geht das so?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
type
TFeldShape = array[0..N-10..N-1of TShape; 
[...]
 public
    FeldShape : TFeldShape;
Grundsätzlich nicht schlecht, aber N soll doch variabel werden. :zwinker: Wie könnte man denn dieses Problem lösen? :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Mi 22.04.15 21:26 
dann mein ich bestimmt elementtyp, ich komm mit den ganzen begriffen nicht so ganz klar :P


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
type
    TFeldShape = array[0..300..30of TShape; 
[...]
 public
    FeldShape : TFeldShape;


ich kann ja so einfach einen höchstwert für die Feldgröße festlegen
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 22.04.15 21:58 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
dann mein ich bestimmt elementtyp, ich komm mit den ganzen begriffen nicht so ganz klar :P
Alles OK. ;)

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
ich kann ja so einfach einen höchstwert für die Feldgröße festlegen
Perfekt! :zustimm: Genau so, einfach einen Maximalwert festlegen. Aaaaber... dann bitte auch als Konstante wie N deklarieren (z.B. als "Nmax"). :idea: Wie würde das dann aussehen? :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Mi 22.04.15 22:47 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
const
  Nmax = 35
[...]
type
    TFeldShape = array[0..NMax-10..NMAX-1of TShape; 
[...]
 public
    FeldShape : TFeldShape;

wäre das dann so?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 22.04.15 23:20 
Moin!

Top! :zustimm:

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. :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Do 23.04.15 18:26 
ausblenden 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; // das neue Shape soll auf dem Formular (=Self) angezeigt werden
    snr := x +y *N +1;
    Shape.Name := 'Shape'+inttostr(snr); // Name der Komponente
    Shape.Left := 10+x*25;
    Shape.Top := 80+y*25;
    Shape.Width := 25;
    Shape.Height := 25;
    Shape.OnMouseDown := @Shape1MouseDown; // so weist man eine Methode zu
    FeldShape[x,y] := Shape;
   end;
  ClientHeight := N*25+100;
  ClientWidth := N*25+20;
end;


Ist das dann irgendwie so in der Art?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.04.15 18:36 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
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). :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Do 23.04.15 18:54 
hab ich eingebaut :)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.04.15 12:34 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
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? :zwinker:

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. :idea: Sonst haben wir ein Speicher-Leck (wir fordern Speicher für die Shapes an, aber geben ihn nicht wieder frei :shock:)! Dazu eine Idee? :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Fr 24.04.15 19:36 
Ne der wollte NMax als maximumwert nicht akzeptieren :/

Nee da hab ich leider keine idee :(
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.04.15 20:28 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
Ne der wollte NMax als maximumwert nicht akzeptieren :/
Ja, das hab ich mir schon gedacht. :D Lösung: In der FormCreate-Methode musst du den Maximalwert per Code setzen. :idea:

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
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... :angel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: Fr 24.04.15 21:57 
was ist denn formdestroy? o.O
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.04.15 22:01 
Moin!

Das ist die Methode, die aufgerufen wird, wenn das Formular gelöscht werden soll. :idea: 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. :lupe:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: 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
ausblenden 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(nilthen FeldShape.free;
    FeldShape.free := FeldShape.nil;
   end;
end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.04.15 23:39 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
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. :zustimm:

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 = nilthen
  • Man kann nil einer Variablen auch ganz genau so einfach zuweisen: variable := nil;
Damit solltest du erstmal weiter kommen. :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.