Autor Beitrag
Fabian E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Mo 05.03.07 17:13 
Also jetz habe ich ein problem beim createn eines images.
ausblenden Delphi-Quelltext
1:
Turm[AnzahlTuerme].Image := TImage.Create(Image1);					


"Turm" ist von der klasse "TTurm" abgeleitet un hat eine variable "Image" welche ein TImage ist! :wink:
Außerdem ist "Turm" ein dynamisches Array, welches aber auf jeden fall groß genug ist. dies kann also ausgeschlossen werden.

woran könnte das jetzt liegen?
Wenn ich ein array of image nehme klappt alles wunderbar...
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 05.03.07 17:15 
ausblenden Delphi-Quelltext
1:
Turm[AnzahlTuerme].Image := TImage.Create(Image1);					

Was ist Image1?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Mo 05.03.07 17:19 
Setzt mal statt Image1 > Self ein.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 05.03.07 17:20 
Vielleicht
Zitat:
Turm[AnzahlTuerme-1].Image := TImage.Create(Nil);

_________________
Markus Kinzler.
Fabian E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Mo 05.03.07 17:31 
nope weder self noch nil.
Image1 ist ein ganz normales Image.von delphi erstellt, sprich draufgezogen :wink:
Joar wie gesagt es muss daran liegen dases eine variable von einer klasse ist...weil mit nur einer variablen gehts ja...
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 05.03.07 17:32 
user profile iconFabian E. hat folgendes geschrieben:
nope weder self noch nil.
Image1 ist ein ganz normales Image.von delphi erstellt, sprich draufgezogen :wink:
Joar wie gesagt es muss daran liegen dases eine variable von einer klasse ist...weil mit nur einer variablen gehts ja...

Ich vermute mal eher, daß es an den Grenzen liegt.

_________________
Markus Kinzler.
Fabian E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Mo 05.03.07 17:36 
du meinst das das arry zu klein ist?nein!
mit normaler variable war ein normales array gemeint :wink:
und es ist auch egal was ist für eine zal in "setLength" einsetze...
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 05.03.07 17:37 
Wenn du einen dynamsich array mit 5 Elementen hat, hat das größte Element den Index 4 (0 bis 4 ergibt 5).

_________________
Markus Kinzler.
Fabian E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Mo 05.03.07 17:43 
jup ich weiß! aber darum geht es ja auch gar nicht^^ wenn ich ein  Array of TImage deklariere dann klappt das ja einwandfrei...
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 05.03.07 17:45 
So - nach dem ganzen Hin und Her nun nochmal:
Zeig mal den Code, den du ansprichst, der funktioniert.
user profile iconFabian E. hat folgendes geschrieben:
wenn ich ein  Array of TImage deklariere dann klappt das ja einwandfrei...

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Fabian E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Mo 05.03.07 17:50 
ausblenden Delphi-Quelltext
1:
2:
SetLength(Turm_image,AnzahlTuerme+1);
Turm_image[AnzahlTuerme] := TImage.Create(Image1);

ausblenden Delphi-Quelltext
1:
Turm_image: Array of TImage;					
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Mo 05.03.07 17:59 
Hallo,

warum verwendest du denn ein resourcefressendes TImage? TImage ist eine sichtbare Komponenten, mit den Eigenschaften Owner und Parent. Ich sehe keinen Grund, warum du dies benötigen solltest. Ich würde dir eher TBitmap empfehlen!

Gruß Hape!
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 05.03.07 18:00 
Was bringt es dir denn, Image1 mit der Instanz von TTurm zu verbinden? Verstehe ich net. Ansonsten würde es vlt. helfen, das Image im Konstruktor zu erstellen.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Fabian E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Mo 05.03.07 18:03 
hmm...okay ich werde es mal mit bitmaps versuchen.

Danke!
HelgeLange
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Mo 05.03.07 18:03 
Also ich verstehe immer noch nicht, warum Du drauf bestehst, als Owner Image1 da reinzuschreiben *kopfschüttel*

Aber wenn Du ein dynamisches Array ansprichst, dann mach das lieber so :

ausblenden Delphi-Quelltext
1:
2:
SetLength(Turm_image, Length(Turm_Image)+1);
Turm_image[High(Turm_Image)] := TImage.Create(Self);


Dadurch stellst Du sicher, dass immer ein neues hinmtenangefügt wird.

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Mo 05.03.07 18:39 
Mal gaaaanz langsam. Nochmal wieder gaaanz an den Anfang.

Du möchtest ein Array von Türmen (Array of TTurm) haben, und jeder Turm hat ein Image.

Du hast also dein Array Turm[] und versuchst nun den Elementen dieses Arrays (also den Türmen) ihre Eigenschaft Image zu befüllen, indem du da ein jeweils frisch erzeugtes Image reinschreibst.
ausblenden Delphi-Quelltext
1:
Turm[ArrayIndex].Image := TImage.Create(Image1);					

So weit, so gut.

Und wo bitteschön erzeugst du den Turm????????

Du musst doch sowas hier machen (siehe auch Kommentar im Code):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Turm[ArrayIndex] := TTurm.Create;  //Ich gehe mal davon aus, dass TTurm keine Ableitung 
                                   //von TComponent ist und somit keinen Owner besitzt.
Turm[ArrayIndex].Image := TImage.Create(Image1); //Du kannst den Images ruhig den Owner Image1 verpassen, 
                                   //dann werden die mit der Freigabe von Image1 auch mit freigegeben. 
                                   //Die Türme musst du nachher aber expliziet selber freigeben.


Anm.: Sinnigerweise würde man dann allerdings das Image im Konstruktor des Turms erzeugen. Aber jetzt mal nur so aus Prinzip erstmal.
HelgeLange
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Mo 05.03.07 18:49 
ich muss ja leider sagen, dass ich aus Prinzip eher ne TList nehmen würde als ein dynamisches Array. Liegt einfach daran, dass sie sich besser ver(ge)walten lassen :)

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Mo 05.03.07 19:12 
user profile iconIngoD7 hat folgendes geschrieben:
Anm.: Sinnigerweise würde man dann allerdings das Image im Konstruktor des Turms erzeugen. Aber jetzt mal nur so aus Prinzip erstmal.

Zusatz:
Man kann anscheinend einer Property vom Typ TImage keine write-Statement verpassen. Somit hast man keine Chance, der Eigenschaft Image etwas zuzuweisen. Somit kann es eh nicht so funktionieren, wie es hier die ganze Zeit besprochen wurde. Das Erzeugen des Image muss also im Konstruktor von TTurm geschehen (dort dann der Zugriff auf das der Eigenschaft Image zugrundeliegende private Feld).
Außerdem: Wenn du ein JPG-File als Bild in TImage.Picture bringen willst, muss die Unit jpeg eingebunden sein. Sonst gibt's auch einen Fehler beim Laden des Bildes.

user profile iconHelgeLange hat folgendes geschrieben:
ich muss ja leider sagen, dass ich aus Prinzip eher ne TList nehmen würde als ein dynamisches Array. Liegt einfach daran, dass sie sich besser ver(ge)walten lassen :)

Das sowieso. TObjectList oder TStringList.
Aber er muss ja überhaupt erst einmal seinen Turm zusammengebaut bekommen. Zu diesem Zeitpunkt gehe ich davon aus, dass noch nirgendwo ein Turm created wird.
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Mo 05.03.07 19:38 
user profile iconFabian E. hat folgendes geschrieben:
Image1 ist ein ganz normales Image.von delphi erstellt, sprich draufgezogen :wink:

Meinste du hast auf die Komponentenpalette geklickt und ein Image auf die Form gepappt
und willst das jetzt nur dem Array zuweisen?
ausblenden Delphi-Quelltext
1:
Turm[AnzahlTuerme].Image := Image1;					
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Mo 05.03.07 20:47 
user profile iconCoder hat folgendes geschrieben:
user profile iconFabian E. hat folgendes geschrieben:
Image1 ist ein ganz normales Image.von delphi erstellt, sprich draufgezogen :wink:

Meinste du hast auf die Komponentenpalette geklickt und ein Image auf die Form gepappt
und willst das jetzt nur dem Array zuweisen?
ausblenden Delphi-Quelltext
1:
Turm[AnzahlTuerme].Image := Image1;					

Das will er mit Sicherheit nicht. Jedem Turm im Array ein- und dasselbe Image1 zuweisen, wäre ja dann doch reichlich sinnfrei.

Er will pro Turm im Array ein eigenes Image haben. Diese Images sollen das "auf die Form gepappte" Image als Owner haben. Das ist möglich und das ist auch mit Sicherheit nicht das Problem.

Ich bin so vermessen (sorry!), zu behaupten, dass die Crux in meinen Postings zuvor angesprochen wurde. Wir sollten seine Antwort mal abwarten.