Autor Beitrag
Adam Weishaupt
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 20.03.04 18:52 
Guten Tag,

sagen wir mal ImageX (X soll irgendeine Zahl sein) ist auf den Koordinaten Left=600 Top=150.
Jetzt will ich, dass ImageY (Y soll irgendeine Zahl sein) die Positionen mit ImageX wechselt.

z.B.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
ImageY.Left := 500;
ImageY.Top := 200;

ImageX.Left := 600:
ImageX.Top := 150;


Wenn man auf ImageY klickt, sollen sich die Positionen von den beiden Images umtauschen.
Wie finde ich heraus was X bei ImageX ist bzw. welches Image auf der Position ist?

Moderiert von user profile iconPeter Lustig: Delphi-Tags hinzugefügt
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: Sa 20.03.04 19:06 
du warst schon 3 zeilen an der lösung dran: :D
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Image1Click(Sender: TObject);
var oldx,oldy:integer;
begin
oldx:=image2.Left;
oldy:=image2.Top;
image2.Left:=image1.Left;
image2.Top:=image1.Top;

image1.Left:=oldx;
image1.Top:=oldy;
end;


für image2 sieht das genauso aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Image2Click(Sender: TObject);
var oldx,oldy:integer;
begin
oldx:=image2.Left;
oldy:=image2.Top;
image2.Left:=image1.Left;
image2.Top:=image1.Top;

image1.Left:=oldx;
image1.Top:=oldy;
end;

_________________
Patrick
im zweifelsfall immer das richtige tun!!!
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 20.03.04 19:22 
danke fuer die antwort, aber bei mir ist es so:

ich weiss ja nicht, ob es image2 oder image3 oder image sonstwas ist..

ich will die position z.b. top=500 , left= 150 auslesen, um herauszufinden welches image dort ist..
soll heissen, ich weiss nicht, welches image von z.b. 50 an der position ist und will es herausfinden ;-)

danke nochmal
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Sa 20.03.04 19:53 
Eine Lösung wäre eine Variable Image vom Typ TImage zu definieren und in einer for-Schleife für i von 1 bis zur Anzahl der Images folgendes machen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Image := TImage(FindComponent('Image'+IntToStr(i)));
if (Image.Left = 150and (Image.Top = 500then
  begin
    // Image.Left und Image.Top verändern
  end;

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 20.03.04 20:05 
es funktioniert, vielen dank an euch beiden :-)
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 20.03.04 20:23 
hmm... es funktioniert doch nicht so, wie ich es gedacht habe..
hier der quelltext, den ich geschrieben habe:

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:
var a: Boolean;
    old: TImage;

[...]

procedure TForm1.Image9Click(Sender: TObject);
var i, oldx, oldy: Integer;
begin
  oldx:=image9.left;
  oldy:=image9.top;
  if a=false then
    begin
      image9.Left:=616;
      image9.top:=160;
      a:=true;
    end 
  else 
  if a=true then
    begin
      for i:=1 to 45 do
        begin
          old := TImage(FindComponent('Image'+IntToStr(i)));
          if (old.Left = 616and (old.Top = 160then
            begin
              old.top:=oldx;
              old.left:=oldy;
              image9.Left:=616;
              image9.top:=160;
            end;
        end;
    end;
end;


das problem ist, dass das alte Image (variable: old) ganz ploetzlich nach ganz unten der form.clientheight verschwindet, statt zur alten position von image9.. oh man ein problem nach dem anderen ^^

noch was: die variable: a testet, ob schon ein image auf den koordinaten 616,160 schon ein image ist.. bei true ist eins da, bei false nicht ;-)
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 20.03.04 20:34 
LOOOOOOOOL

ich habe es allein herausgefunden ;-)

ich habe oldx und oldy verwechselt.. nochmals danke an patrick und derDoc :-D