Autor Beitrag
ACID
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53


D7 Pers
BeitragVerfasst: Fr 01.04.05 14:06 
Hi, habe da ein kleines Problem.
Ich habe 49 Images mit den Namen B1 bis B49.
Ich wollte mit einer For To Do Schleife in jedes Bild was zeichnen.
Aber es funktioniert nicht so richtig.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
For x:=1 to 49
 begin
  B+x.canvas.rectangle(0,0,B+x.width,B+x.height);
 end;


Das B+x sollte bewirken das jedes Image der Reihe nach angesprochen wird. Aber es geht nicht.
Bitte helft mir.
Ich danke schon mal im voraus.

Moderiert von user profile iconGausi: Color- durch Delphi-Tags ersetzt.
Moderiert von user profile iconGausi: Topic aus Sonstiges verschoben am Fr 01.04.2005 um 14:26
Dose
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Fr 01.04.05 14:16 
Das kann so leider nicht funktionieren. Du müsstest die Bilder vorher in ein Array Packen, also Beispielsweise Bilder = array [1..49] of TBitmap. Da kommen dann alle rein. Nun kannst du die einfach ansprechen mit Bilder[x].
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 01.04.05 14:24 
Hallo und :welcome:
Das mit dem Array ist eine Variante. Alternativ kann ich dir empfehlen, dich mal über Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT zu erkundigen.

_________________
We are, we were and will not be.
demo88
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Ubuntu 6.04, Win XP
Delphi 7
BeitragVerfasst: Fr 01.04.05 14:47 
So sollte es gehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  c: Tcomponent;
begin
For x:=1 to 49   
  begin   
    c:=Findcomponent('B'+inttostr(x));
    (c as Timage).canvas.rectangle(0,0,B+x.width,B+x.height);   
  end;
end;
ACID Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53


D7 Pers
BeitragVerfasst: Fr 01.04.05 16:43 
Danke für die schnelle antwort.
Aber leider funktioniert der Code nicht.

var
c: Tcomponent;
begin
For x:=1 to 49
begin
c:=Findcomponent('B'+inttostr(x));
(c as Timage).canvas.rectangle(0,0,B+x.width,B+x.height);
end;
end;

Die Images sind TImage.
Gibt es auch ne andere variante?
demo88
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Ubuntu 6.04, Win XP
Delphi 7
BeitragVerfasst: Fr 01.04.05 18:23 
Da brauchst du keine andere Lösung, du hättest nur ein bisschen mitdenken müssen :twisted:

Hier der Code nochmal komplett auf deine Bedürfnisse angepasst (Funktioniert zu 100%):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  c: Tcomponent;
  x: byte;
begin
For x:=1 to 49 do
  begin
    c:=Findcomponent('B'+inttostr(x));
    with (c as Timage) do
      begin
        canvas.rectangle(00, width, height);
      end;
  end;
end;
ACID Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53


D7 Pers
BeitragVerfasst: Fr 01.04.05 19:41 
Leider funktioniert das bei mir nicht.
Im projekt1.exe ist eine Exception der Klasse EAccessViolation aufgetreten.
Zugriffsverletzung bei Adresse 0044F71B in Modul Projekt1.exe .
Lesen von Adresse 00000048 .

Ich Benutze Delphi 7

Ich Habe mal das Prog angehangen.
Einloggen, um Attachments anzusehen!
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Fr 01.04.05 20:08 
Du hast ein Image20 drin...mit anderen Worte es fehlt irgendein B.
Da nirgends überprüft wird, ob der Component überhaupt gefunden wurde gibts ne Exception.

Deswegen, diesen Code verwenden und für die Zukunft merken:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var i : integer; 
    img : Timage;
begin
 for i := 1 to 49 do
  begin
   img := TImage(FindComponent('B' + inttostr(i)));
   if img <> nil then 
    img.canvas.rectangle(0,0,img.width,img.height)
  end;
end;
ACID Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53


D7 Pers
BeitragVerfasst: Fr 01.04.05 20:18 
Tausend Dank, das IMAGE20 sollte natürlich B20 heisen.
Tja so kans einem gehen, kleiner fehler grosses Problem.
Hab es umgeändert und es funktioniert.

Tausend dnak nochmal.
CU