Autor Beitrag
shrubman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: So 07.11.04 13:51 
Ich habe einen Button und ich möchte dass wenn ich darauf klicke beim ersten mal ein bild angezeigt wird und beim zweiten mal klicken ein anderes wie ist dies umsetzbar ??
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: So 07.11.04 13:58 
Mit einer globalen Variable (oder auch im private-Teil deines Formulars):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  x : Boolean;
//...
procedure TForm1.ButtonClick(Sender : TObject);
begin
  if x then
  begin
    x:=False;
    //Bild anzeigen
  end else
  begin
    x:=True;
    //Bild ausblenden
  end;
end;

Prinzip klar?

Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: So 07.11.04 14:08 
wenn du die bilder von 2 unabhängigen image-komponenten anzeigen läst kannst du das so machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if image1.Visible then
  begin
    image1.Visible:=false;
    image2.Visible:=true;
  end
  else
  begin
    image1.Visible:=true;
    image2.Visible:=false;
  end;
end;

zur designtime must du aber noch eines der beiden bilder visible schalten und das andere nicht.

wenn du jedoch nur eine image-komponeten verwenden und den inhalt dynamisch laden willst. must du anders vorgehen.

_________________
Patrick
im zweifelsfall immer das richtige tun!!!
shrubman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: So 07.11.04 14:22 
Titel: hmm
ich glaub das ist nicht die lösung denn ich will hangman proggen und wenn ein buchstabe falsch ist soll das nächste bild angezeigt werden vom galgen und so weiter....
shrubman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: So 07.11.04 14:28 
klappt doch damit THX!!!
shrubman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: So 07.11.04 14:49 
Warum zeigt er jetzt gleich Image3 an??

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:
procedure TForm1.Button2Click(Sender: TObject);
var A,Wort:string;
    Z:Boolean;
begin
Wort:=Label2.Caption;
A:=Edit2.Text;
Z:= Pos(A, Wort) <> 0;
if
Z=true     // Fall Z true ist ( Falls Z die Position A im Wort vertritt )
then
begin
Label1.Caption:=Label1.Caption +A;   // Dann schreibt diesen Buchstaben ins Label 1
end
else
begin
Label3.Caption:=Label3.Caption +A;
if
Image1.Visible=true      // Andersfall in Label 3
then
begin
Image1.Visible:=false;
Image2.Visible:=true;
end else Image1.Visible:=true;  // Falls  Image 1 true ist beim nächsten klicken Image 1 false machen und Image 2 true
begin
if
Image2.Visible=true
then
begin
Image2.Visible:=false;
Image3.Visible:=true;
end else Image2.Visible:=true;
end;
end;
end;


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: So 07.11.04 15:02 
Formatier den Quelltext maln bißchen, damit man ihn auch lesen kann.

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
shrubman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: So 07.11.04 15:27 
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:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
procedure TForm1.Button2Click(Sender: TObject);
var A,Wort:string;
    Z:Boolean;
begin

Wort:=Label2.Caption;
A:=Edit2.Text;
Z:= Pos(A, Wort) <> 0;
   if
Z=true     // Fall Z true ist ( Falls Z die Position A im Wort vertritt )
   then

begin

Label1.Caption:=Label1.Caption +A;   // Dann schreibt diesen Buchstaben ins Label 1

end

   else

begin

Label3.Caption:=Label3.Caption +A;

   if
Image1.Visible=true      // Andersfall in Label 3
   then
begin
Image1.Visible:=false;
Image2.Visible:=true;

end 
   else Image1.Visible:=true;
 
begin

   if
Image2.Visible=true

   then

begin
Image2.Visible:=false;
Image3.Visible:=true;
end else Image2.Visible:=true;

end;
end;
end;
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: So 07.11.04 15:34 
Das ist nicht unbedingt besser, oder wirds nur bei mir so schief angezeigt?

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: Mo 08.11.04 14:20 
so sieht das doch schon viel besser aus:
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:
procedure TForm1.Button2Click(Sender: TObject);
var
  A, Wort: string;
  Z: Boolean;
begin
  Wort := Label2.Caption;
  A := Edit2.Text;
  Z := Pos(A, Wort) <> 0;
  if
    Z = true {// Fall Z true ist ( Falls Z die Position A im Wort vertritt )  } then
  begin
    Label1.Caption := Label1.Caption + A; // Dann schreibt diesen Buchstaben ins Label 1
  end
  else
  begin
    Label3.Caption := Label3.Caption + A;
    if
      Image1.Visible = true {// Andersfall in Label 3  } then
    begin
      Image1.Visible := false;
      Image2.Visible := true;
    end else Image1.Visible := true; // Falls  Image 1 true ist beim nächsten klicken Image 1 false machen und Image 2 true
    begin
      if
        Image2.Visible = true then
      begin
        Image2.Visible := false;
        Image3.Visible := true;
      end else Image2.Visible := true;
    end;
  end;
end;

wie man einen code ordentlich programmiert kannst du übrigends hier nachlesen:
www.luckie-online.de...kel/CodeDesign.shtml
alternativ hat borland auch einen styleguide herausgegeben. leider hab ich da grad keinen link dazu.

aber zu deinem problem:
hast du in deinem objektinspektor die eigenschaft visible auf "false" gestellt?

_________________
Patrick
im zweifelsfall immer das richtige tun!!!
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: Mo 08.11.04 14:32 
ich will die edit funktion wieder haben :motz:
das kommt davon, wenn man den code mal schnell automatisch formatieren lässt :?
ok die von hand überarbeitete fassung:
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:
procedure TForm1.Button2Click(Sender: TObject);
var
  A, Wort: string;
  Z: Boolean;
begin
  Wort := Label2.Caption;
  A := Edit2.Text;
  Z := Pos(A, Wort) <> 0;

  if Z = true then {// Fall Z true ist ( Falls Z die Position A im Wort vertritt )  }
  begin
    Label1.Caption := Label1.Caption + A; // Dann schreibt diesen Buchstaben ins Label 1
  end
  else
  begin
    Label3.Caption := Label3.Caption + A;

    if Image1.Visible = true then {// Andersfall in Label 3  }
    begin
      Image1.Visible := false;
      Image2.Visible := true;
    end
    else
    begin //!!patrick edit: "Image1.Visible := true;" muss doch in den begin-block oder?
      Image1.Visible := true; // Falls  Image 1 true ist beim nächsten klicken Image 1 false machen und Image 2 true

      if Image2.Visible = true then
      begin
        Image2.Visible := false;
        Image3.Visible := true;
      end
      else
      begin
        Image2.Visible := true;
      end;
    end;
  end;
end;

ich glaub ich hab auch noch einen coding-fehler gefunden (siehe meinem edit).
ich hoffe ich hab jetzt auf die schnelle nicht nochmals was übersehen.
ich muss weg...

_________________
Patrick
im zweifelsfall immer das richtige tun!!!
shrubman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Mo 08.11.04 16:57 
danke!!
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: Mo 08.11.04 17:26 
gern geschehen aber:
was war denn jetzt das problem :?:

_________________
Patrick
im zweifelsfall immer das richtige tun!!!