Autor Beitrag
Tigu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Do 08.03.07 17:08 
Hallo!

Ich habe mal wieder ein Problem, welches für euch bestimmt gar nicht so groß ist, aber meine Delphikenntnisse sind recht beschränkt. :?

Ich habe in ein StringGrid Bilder geladen. Nun soll überprüft werden, ob in allen Zellen ein Bild ist und ob Bild1 in der angeklickten Zelle ist.

Mien Ansatz:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
....
if ((feld.Cells[col,Row]<>'') and 
    (feld.cells[ACol,ARow]             ????=Bild1???)) then 
 begin
.....


Könnt ihr mir bitte helfen dies zu vervollständigen und/ oder richtig zu stellen. :eyes:

Schon mal vielen Dank für eure Hilfe

Tigu

PS: Ich bin mir nicht sicher, ob das der richtige Forenteil dafür ist, wenn nicht bitte verschiebn.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 08.03.07 20:47 
Hallo,

wenn Du Bilder in dein Grid geladen hast, dann weißt Du doch wo welches Bild geladen wurde. :wink:

Solltest Du nicht wissen wo welches Bild geladen wurde, dann musst Du Dir Zelle und Bildindex beim Laden irgendwo speichern, um die Informationen später abfragen zu können.

Wie lädst Du die Bilder?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Do 08.03.07 21:06 
user profile iconLannes hat folgendes geschrieben:

wenn Du Bilder in dein Grid geladen hast, dann weißt Du doch wo welches Bild geladen wurde. :wink:


Leider nicht, läuft per Zufall. 8)
Außerdem soll das Ganze ein Spiel werden, bei dem die Bilder immer wieder wechseln.
Hast du eine Idee, wie man den Quelltext oben verbessern/vervollständigen kann?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 08.03.07 21:14 
Hallo,

also nochmal meinen zweiten Satz, etwas ergänzt:
Solltest Du nicht wissen wo welches Bild geladen wurde(z.B. Bilder per Random eingefügt), dann musst Du Dir Zelle und Bildindex beim Laden(da hast Du auf jeden Fall die Infos) irgendwo speichern, um die Informationen später abfragen zu können.

user profile iconTigu hat folgendes geschrieben:
Hast du eine Idee, wie man den Quelltext oben verbessern/vervollständigen kann?

wenn Du mir die Frage von vorhin beantwortest, sehr wahrscheinlich :wink:

user profile iconLannes hat folgendes geschrieben:
Wie lädst Du die Bilder?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Do 08.03.07 21:24 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
bilder[i] := TJPEGImage.Create;   // leeres Bildobjekt erzeugen
bilder[i].LoadFromFile('BM' + IntToStr(i) + '.jpg');  // Bild laden
...


Reicht dir das?
Danke
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 08.03.07 23:24 
Hallo,

sehe da nicht wie die Bilder ins Grid geladen werden :nixweiss:

Ich Versuch es mal mit Raten.

- Zufallszahl wird erzeugt
- diese dient als Index um aus Deinem Bilderarray ein Bild auszuwählen

Diesen Index musst Du Dir jetzt irgendwo mit Bezug zur jeweiligen Zelle Speichern.
Dafür bieten sich nun mehrere Möglichkeiten an:

- ein Array of Integer in der Größe des Grids
- einen Pointer auf den Index in das schon im StringGrid vorhandene Array Objects
- oder den Index als String in StringGrid.Cells
- ...

nehmen wir mal die dritte Möglichkeit, dann könnte der Code zur Abfrage etwa so aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
if ((Grid.Cells[ACol,ARow] <> '') and   
    (StrToInt(Grid.Cells[ACol,ARow]) = 2)) then   
     //...

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Do 08.03.07 23:34 
Sorry, was vergessen.

Rest: OnDrawCell-Event
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var nr:integer;
.....
if (feld.Cells[ACol,ARow]<>'') then begin
    nr:=StrToInt(feld.Cells[ACol,ARow]);
    with feld.Canvas do
      Draw(Rect.Left, Rect.Top, bilder[nr]);
...


müsste jetzt aberstimmmen, oder?
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Fr 09.03.07 01:28 
Moin ...,
also ich würde auch, wie Lannes schon schrieb, ein Index-Array nehmen oder aber an die jeweilige Zelle ein Object mit dem Bild anheften! Vorteil wäre das die Zelle schon mit dem jeweiligen Bild verknüpft ist und könnte dann bspw. auf nil prüfen ob ein Object existiert.

LG Mario
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 09.03.07 14:51 
Hallo,
user profile iconTigu hat folgendes geschrieben:
müsste jetzt aberstimmmen, oder?
bezogen auf den mir bis jetzt bekannten Code, ja.

user profile iconHobby-Programmierer hat folgendes geschrieben:
... und könnte dann bspw. auf nil prüfen ob ein Object existiert....
aber aufpassen, denn bei der Erst-Initialisierung wird jedes Object des Arrays Objects[col,row] automatisch mit Pointer(0) vorbelegt, und ist somit nicht nil.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Fr 09.03.07 16:15 
Hallo Lannes ...,
natürlich auf 0 prüfen :oops:
Hier hatte ich mal ein Beispiel dafür gepostet!

LG Mario
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Fr 09.03.07 18:02 
Danke :)