Autor Beitrag
christian_m
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 10.05.07 18:54 
Hi @ all!

Ich versuche ein Image auf die Position eines Feldes zu platzieren, indem ich mit einer if-Anweisung überprüfe ob die Tagnummer des Images = der Tagnumemr des Shapes ist.

Hier mein Code:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
procedure TForm1.Image1DblClick(Sender: TObject);
begin
 case Zahl of
  1:
   begin
   image1.tag:= image1.tag+1;
   if image1.tag=shape1.tag
    then
     begin
      image1.top:=shape1.top-15;
      image1.left:=shape1.left+5;
      label2.caption:=IntToStr(image1.tag);
      end
   else if image1.tag=shape2.tag
    then
     begin
      image1.top:=shape2.top-15;
      image1.left:=shape2.left+5;
      label2.caption:=IntToStr(image1.tag);
      end
...
...
...
   else if image1.tag=shape11.tag
    then
     begin
      image1.top:=shape11.top-15;
      image1.left:=shape11.left+5;
      label2.caption:=IntToStr(image1.tag);
      end
   else if image1.tag=shape12.tag
    then
     begin
      image1.top:=shape12.top-15;
      image1.left:=shape12.left+5;
      label2.caption:=IntToStr(image1.tag);
      end;

   end;


Da sich das Image hier nur bei einer 1 bewegt, müsste ich das noch bis zur zahl 6 durchmachen.

Kann mir jemdand helfen das zu vereinfachen?

//PS Mit FindComponent versteh ich das nicht so ganz, da ich noch nicht soviel mit delphi gemacht habe(1.5 Jahre)

mfg Chris
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 10.05.07 19:02 
Zunächst einmal, warum fragst Du denn zwei mal das gleiche ab?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
if image1.tag=shape1.tag
   then
     begin
      image1.top:=shape1.top-15;
      image1.left:=shape1.left+5;
      label2.caption:=IntToStr(image1.tag);
      end
...

else if image1.tag=shape11.tag
    then
     begin
      image1.top:=shape11.top-15;
      image1.left:=shape11.left+5;
      label2.caption:=IntToStr(image1.tag);
      end 
...
hui1991
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Do 10.05.07 19:23 
Hi,

das hier ist viel kürzer und schneller (zum tippen) als deins:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TFOrm1.Image1DB1Click(Sender: TObject);
var
  x: Integer;
begin
  if Zahl = 1 then begin
    image1.tag := image1.tag + 1;
    for x := 1 to 12 do begin
      if image1.tag = TShape(FindComponent('Shape'+inttostr(x))).tag then
      begin
        image1.top := TShape(FindComponent('Shape'+inttostr(x))).top - 15;
        image1.left := TShape(FindComponent('Shape'+inttostr(x))).left + 5;
        label2.caption := IntToStr(image1.tag);
        break;
      end
    end;
  end;
end;


Mit einsatz von FindComponent gelernt aus diesem Thema:
www.delphi-forum.de/...58798&highlight=

@Marc.
Hast du was getrunken ^^ *scherz*
Ehm man sieht da sehr undeutlich das da eine 1 und eine 11 da steht. ^^

@COde
Müsste klappen

Und noch sehr viel Spass beim Programmieren und Fehler suchen^^ (und den Rest den man da noch braucht)

MfG
hui1991

edit://
Mir ist grad dies ins Auge gestochen.
user profile iconchristian_m hat folgendes geschrieben:

Da sich das Image hier nur bei einer 1 bewegt, müsste ich das noch bis zur zahl 6 durchmachen.


Das heißt es gibt mehr Images?
Dann gibt jeden dieses Klick und änder Image1 in TImage(Sender) um z. B.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TFOrm1.Image1DB1Click(Sender: TObject);
var
  x: Integer;
begin
  if Zahl = 1 then begin
    TImage1(Sender).tag := TImage1(Sender).tag + 1;
    for x := 1 to 12 do begin
      if TImage1(Sender).tag = TShape(FindComponent('Shape'+inttostr(x))).tag then
      begin
        TImage1(Sender).top := TShape(FindComponent('Shape'+inttostr(x))).top - 15;
        TImage1(Sender).left := TShape(FindComponent('Shape'+inttostr(x))).left + 5;
        label2.caption := IntToStr(TImage1(Sender).tag);
        break;
      end
    end;
  end;
end;


Also.. jedes Image bekommt das, und dieses Image was angeklickt von dort werden die Daten genommen^^


Zuletzt bearbeitet von hui1991 am Do 10.05.07 19:32, insgesamt 1-mal bearbeitet
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 10.05.07 19:28 
user profile iconhui1991 hat folgendes geschrieben:

@Marc.
Hast du was getrunken ^^ *scherz*
Ehm man sieht da sehr undeutlich das da eine 1 und eine 11 da steht. ^^


Ehm ja, vllt. sollte ich meine Augen das nächste Mal etwas weiter öffnen. :roll:
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 10.05.07 19:52 
Vielen Dank für die schnelle Hilfe, besonders hui1991!!

mfg Chris
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 10.05.07 20:01 
Zitat:
hui1991
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
 
procedure TFOrm1.Image1DB1Click(Sender: TObject);
var
  x: Integer;
begin
  if Zahl = 1 then begin
    image1.tag := image1.tag + 1;
    for x := 1 to 12 do begin
      if image1.tag = TShape(FindComponent('Shape'+inttostr(x))).tag then
      begin
        image1.top := TShape(FindComponent('Shape'+inttostr(x))).top - 15;
        image1.left := TShape(FindComponent('Shape'+inttostr(x))).left + 5;
        label2.caption := IntToStr(image1.tag);
     //  <span style="color: red"> break;</span>
      end
    end;
  end;
end;


Jetzt hab ich doch noch eine Frage:
wofür steht das break am ende??
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 10.05.07 20:03 
ohhhhhhhhhhhhhh bin ich blöd!!!!!!!!!!!!!!!!!1

steht das break zufällig dort um die for-Schleife zu beenden?^^

mfg Chris
Corpsman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228

KUbuntu 10.4
Lazarus
BeitragVerfasst: Do 10.05.07 20:04 
Break = Beenden der Aktuellen Schleife ( While , Unitil )

Exit = Beenden der Aktuell aufgerufenen Prozedur

_________________
--
Just Try it.
Timosch
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1314

Debian Squeeze, Win 7 Prof.
D7 Pers
BeitragVerfasst: Fr 11.05.07 17:05 
Und falls du es irgendwann mal brauchen solltest: continue = aktuellen Schleifendurchgang abbrechen und mit nächstem Durchgang fortfahren.

_________________
If liberty means anything at all, it means the right to tell people what they do not want to hear. - George Orwell