![]() |
Images Arrays zuordnen!
Ja das möchte ich machen und ich habe auch schon in anderen Foren geschaut leider bin ich zu blöd kann ich bitte hilfe haben?
(Mindmaster für InfoAG an der Schule soll das werden)
Delphi-Quellcode:
*incompatible types: 'Integer' and 'TImage' muss ich das jezt anders definiern also nich in integer?
unit mastermind;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Image1: TImage; Image2: TImage; Image3: TImage; Image4: TImage; Image5: TImage; Image6: TImage; Image7: TImage; Image8: TImage; Image9: TImage; Image10: TImage; Image11: TImage; Image12: TImage; Image13: TImage; Image14: TImage; Image15: TImage; Image16: TImage; Image17: TImage; Image18: TImage; Image19: TImage; Image20: TImage; Image21: TImage; Image22: TImage; Image23: TImage; Image24: TImage; Image25: TImage; Image26: TImage; Image27: TImage; Image28: TImage; Image29: TImage; Image30: TImage; Image31: TImage; Image32: TImage; Image33: TImage; Image34: TImage; Image35: TImage; Image36: TImage; Image37: TImage; Image38: TImage; Image39: TImage; Image40: TImage; Image41: TImage; Image42: TImage; Image43: TImage; Image44: TImage; Image45: TImage; Image46: TImage; Image47: TImage; Image48: TImage; Image49: TImage; Image50: TImage; Image51: TImage; Image52: TImage; Image53: TImage; Image54: TImage; Image55: TImage; Image56: TImage; RadioGroup1: TRadioGroup; RadioGroup2: TRadioGroup; RadioGroup3: TRadioGroup; RadioGroup4: TRadioGroup; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; y: integer; Farbtipp: array[0..y,0..3] of Integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin {RadioButton1} Farbtipp[0,0]:=Image1;//<--das soll jeweils einem Feld zugeordnet werden aber er sagt immer * if RadioGroup1.ItemIndex=0 then Image1.Picture.LoadFromFile('Blau.bmp'); if RadioGroup1.ItemIndex=1 then Image1.Picture.LoadFromFile('Rot.bmp'); if RadioGroup1.ItemIndex=2 then Image1.Picture.LoadFromFile('Grün.bmp'); if RadioGroup1.ItemIndex=3 then Image1.Picture.LoadFromFile('Gelb.bmp'); if RadioGroup1.ItemIndex=4 then Image1.Picture.LoadFromFile('Braun.bmp'); if RadioGroup1.ItemIndex=5 then Image1.Picture.LoadFromFile('Orange.bmp'); {RadioButton2} Farbtipp[0,1]:=image2; if RadioGroup2.ItemIndex=0 then Image2.Picture.LoadFromFile('Blau.bmp'); if RadioGroup2.ItemIndex=1 then Image2.Picture.LoadFromFile('Rot.bmp'); if RadioGroup2.ItemIndex=2 then Image2.Picture.LoadFromFile('Grün.bmp'); if RadioGroup2.ItemIndex=3 then Image2.Picture.LoadFromFile('Gelb.bmp'); if RadioGroup2.ItemIndex=4 then Image2.Picture.LoadFromFile('Braun.bmp'); if RadioGroup2.ItemIndex=5 then Image2.Picture.LoadFromFile('Orange.bmp'); {RadioButton3} if RadioGroup3.ItemIndex=0 then Image3.Picture.LoadFromFile('Blau.bmp'); if RadioGroup3.ItemIndex=1 then Image3.Picture.LoadFromFile('Rot.bmp'); if RadioGroup3.ItemIndex=2 then Image3.Picture.LoadFromFile('Grün.bmp'); if RadioGroup3.ItemIndex=3 then Image3.Picture.LoadFromFile('Gelb.bmp'); if RadioGroup3.ItemIndex=4 then Image3.Picture.LoadFromFile('Braun.bmp'); if RadioGroup3.ItemIndex=5 then Image3.Picture.LoadFromFile('Orange.bmp'); {RadioButton4} if RadioGroup4.ItemIndex=0 then Image4.Picture.LoadFromFile('Blau.bmp'); if RadioGroup4.ItemIndex=1 then Image4.Picture.LoadFromFile('Rot.bmp'); if RadioGroup4.ItemIndex=2 then Image4.Picture.LoadFromFile('Grün.bmp'); if RadioGroup4.ItemIndex=3 then Image4.Picture.LoadFromFile('Gelb.bmp'); if RadioGroup4.ItemIndex=4 then Image4.Picture.LoadFromFile('Braun.bmp'); if RadioGroup4.ItemIndex=5 then Image4.Picture.LoadFromFile('Orange.bmp'); end; procedure TForm1.Button3Click(Sender: TObject); begin close end; end. |
Re: Images Arrays zuordnen!
Ändere das mal ab von integer in TImage.
[edit] Außerdem würde ich das eher so machen:
Delphi-Quellcode:
[/edit]
procedure TForm1.Button1Click(Sender: TObject);
const Bilder: array[0..5] of string = ('Blau','Rot','Gruen','Gelb','Braun','Orange'); begin {RadioButton1} Image1.Picture.LoadFromFile(Bilder[RadioGroup1.ItemIndex] + '.bmp'); {RadioButton2} Image2.Picture.LoadFromFile(Bilder[RadioGroup2.ItemIndex] + '.bmp'); {RadioButton3} Image3.Picture.LoadFromFile(Bilder[RadioGroup3.ItemIndex] + '.bmp'); {RadioButton4} Image4.Picture.LoadFromFile(Bilder[RadioGroup4.ItemIndex] + '.bmp'); end; |
Re: Images Arrays zuordnen!
Kommt wieder ne fehler meldung zu der Zeile
Konstant espression expected |
Re: Images Arrays zuordnen!
Bei einem statischen Array musst du auch statische Grenzen angeben (keine Variablen)
|
Re: Images Arrays zuordnen!
Stimmt, array[0..Variable] geht nicht.
|
Re: Images Arrays zuordnen!
Schon mal dran gedacht, eine Funktion für die Zuordnung zwischen Index und Bilddatei einzusetz en ?
Delphi-Quellcode:
Bau mal diese Funktion ein und wenn du gut bist, stellst du die IF-Anweisungen auf ein Case um.
function GetBildDatei(index:integer):string;
begin if index=0 then result := 'Blau.bmp' else if index=1 then result := 'Rot.bmp' else ... |
Re: Images Arrays zuordnen!
Oder gleich ein konstantes Array (siehe Edit #2).
|
Re: Images Arrays zuordnen!
const Bilder: array[0..5] of string = ('Blau','Rot','Gruen','Gelb','Braun','Orange');
vielen dank erstmal :lol: aber könntest du mir bitte noch kurz die zeile oben erklären und wie ich die unter var definiere? äh und auch danke für deinen Lösungsvorschlag aber ich weis noch nicht mal was nen case ist ich will das erstmal so fertig kriegen und dann kann ich mir angucken was das ist ähm und dann wollte ich noch wissen ob man x:=1 y:=2 Z:=3 w:=4 auch für image1 schreiben kann image(x+4*i) i ist die schleife for i........ 0 to 6 |
Re: Images Arrays zuordnen!
aslo das mit den farben versteh ich ja
cons (irgendwas mit konstanten arrays oder?) |
Re: Images Arrays zuordnen!
Welche Zeile meinst Du jetzt? Wenn Du dynamisch eine Komponente ansprechen willst, kannst Du das auch mit
![]() |
Re: Images Arrays zuordnen!
Zitat:
![]() |
Re: Images Arrays zuordnen!
x:=1
y:=2 Z:=3 w:=4 auch für image1 schreiben kann image(x+4*i) i ist die schleife for i........ 0 to 6 könnt ihr mir noch kurz sagen ob das geht? und dann noch wie ich das const array in var definiere |
Re: Images Arrays zuordnen!
Delphi-Quellcode:
Ein konstantes Array in einer Var definieren? :gruebel:
FindComponent('Image' + inttostr(x+4*i))
Oder meinst Du sowas?
Delphi-Quellcode:
var Bilder: array[0..5] of string;
begin Bilder[0] := 'Blau'; Bilder[1] := 'Gruen'; ... end; |
Re: Images Arrays zuordnen!
var
Form1: TForm1; array[0..5] of string; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin const Bilder: array[0..5] of string = ('Blau','Rot','Gruen','Gelb','Braun','Orange'); begin {RadioButton1} Image1.Picture.LoadFromFile(Bilder[RadioGroup1.ItemIndex] + '.bmp'); {RadioButton2} Image2.Picture.LoadFromFile(Bilder[RadioGroup2.ItemIndex] + '.bmp'); {RadioButton3} Image3.Picture.LoadFromFile(Bilder[RadioGroup3.ItemIndex] + '.bmp'); {RadioButton4} Image4.Picture.LoadFromFile(Bilder[RadioGroup4.ItemIndex] + '.bmp'); end; end; procedure TForm1.Button3Click(Sender: TObject); begin close end; end. so hab ich das jetzt gemacht aber das funktioniert nicht! |
Re: Images Arrays zuordnen!
Was bedeutet, funktioniert nicht?
|
Re: Images Arrays zuordnen!
declaration expected but const found
und lacht mich nicht aus aber ich bin nun mal nen total noob |
Re: Images Arrays zuordnen!
vor dem const kommt kein begin
|
Re: Images Arrays zuordnen!
Zitat:
Delphi-Quellcode:
das
const
Delphi-Quellcode:
weg und nach
begin
Delphi-Quellcode:
auch..dann solltes es gehen!
image4.....
|
Re: Images Arrays zuordnen!
Danke schonmal aber es geht immer noch nicht:
Project Logiktrainer.exe raised exception class EAccessViolation with message 'Access violation at address 00403EC4 in modul 'Logiktrainer.exe'. Write of address 0057008F'. Process stopped. Use Step or Run to continue. diese meldung kommt dann var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); const Bilder: array[0..5] of string = ('Blau','Rot','Grün','Gelb','Braun','Orange'); begin {RadioButton1} Image1.Picture.LoadFromFile(Bilder[RadioGroup1.ItemIndex] + '.bmp'); {RadioButton2} Image2.Picture.LoadFromFile(Bilder[RadioGroup2.ItemIndex] + '.bmp'); {RadioButton3} Image3.Picture.LoadFromFile(Bilder[RadioGroup3.ItemIndex] + '.bmp'); {RadioButton4} Image4.Picture.LoadFromFile(Bilder[RadioGroup4.ItemIndex] + '.bmp'); end; procedure TForm1.Button3Click(Sender: TObject); begin close end; end. und so sieht das Programm jetzt aus |
Re: Images Arrays zuordnen!
Bei welchem Index?
|
Re: Images Arrays zuordnen!
Ich wuerde sagen, Du solltest den Pfad der Bilder mal zusaetzlich mit angeben...das Programm findet sie sicher nicht.
Delphi-Quellcode:
Image1.Picture.LoadFromFile('c:\bilder\'+Bilder[RadioGroup1.ItemIndex] + '.bmp');
|
Re: Images Arrays zuordnen!
thx thx thx
i love you all :love: :love: :love: wer hier nen problem hat findet immer ne Lösung !!! :dp: |
Re: Images Arrays zuordnen!
Delphi-Quellcode:
hab doch noch mal ne frage (wieso geht das nicht)
var
Form1: TForm1; x, y, z, w: integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); const Bilder: array[0..5] of string = ('Blau','Rot','Grün','Gelb','Braun','Orange'); var i:integer; begin for i := 0 to 5 do begin x:=1; y:=2; Z:=3; w:=4; {RadioButton1} FindComponent('Image' + IntToStr(x+4*i)).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup1.ItemIndex] + '.bmp'); {RadioButton2} FindComponent('Image' + IntToStr(y+4*i)).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup2.ItemIndex] + '.bmp'); {RadioButton3} FindComponent('Image' + IntToStr(z+4*i)).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup3.ItemIndex] + '.bmp'); {RadioButton4} FindComponent('Image' + IntToStr(w+4*i)).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup4.ItemIndex] + '.bmp'); end; end; procedure TForm1.Button3Click(Sender: TObject); begin close end; end. Fehlermeldung: undeclared indentifier: 'Picture' |
Re: Images Arrays zuordnen!
Das Ergebnis von .FindComponent() ist ein TComponent. Diese Klasse kennt die Eigenschaft .Picture nicht. Deshalb musst du das Ergebnis entsprechen Casten:
Delphi-Quellcode:
(FindComponent('Image' + IntToStr(x+4*i)) as TBitmap).Picture. ...
|
Re: Images Arrays zuordnen!
sry geht aber leider auch nicht
'TBitmap' and 'TComponent' incompatible types |
Re: Images Arrays zuordnen!
Versuchs mal mit TImage
|
Re: Images Arrays zuordnen!
danke hat funktioniert aber wie kann ich es machen das die schleife nacht jedem Button Klick nur einmal durchläuft und ich dann die Radiobox eingabe ändern kann?
Delphi-Quellcode:
var
Form1: TForm1; x, y, z, w: integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); const Bilder: array[0..5] of string = ('Blau','Rot','Grün','Gelb','Braun','Orange'); var i: integer; begin for i:= 0 to 5 do begin x:=1; y:=2; Z:=3; w:=4; {RadioButton1} (FindComponent('Image' + IntToStr(x+4*i)) as TImage).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup1.ItemIndex] + '.bmp'); {RadioButton2} (FindComponent('Image' + IntToStr(y+4*i)) as TImage).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup2.ItemIndex] + '.bmp'); {RadioButton3} (FindComponent('Image' + IntToStr(z+4*i)) as TImage).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup3.ItemIndex] + '.bmp'); {RadioButton4} (FindComponent('Image' + IntToStr(w+4*i)) as TImage).Picture.LoadFromFile('H:\USB-Stick\logictrainer\'+Bilder[RadioGroup4.ItemIndex] + '.bmp'); end; end; |
Re: Images Arrays zuordnen!
Di Schleife sollte doch nur einmal durchlaufen werden. Vielleicht hilft es den Button zu deaktivieren.
|
Re: Images Arrays zuordnen!
ich weiß nicht ob du mastermind kennst aber wenn ich den Button klicke habe ich nin einer Reihe 4 Images mit farben und dass 7 mal übereinander so dass jede Reihe andere farben hat das heißt nach dem siebten mal ist das erst zu ende und mann konnte jedesmal die Farben ändern
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:57 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz