![]() |
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
![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:32 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