Autor Beitrag
Marat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 25



BeitragVerfasst: Sa 26.06.04 14:00 
Hallo Delphi Freunde!

So.Mit den Sachen wie "Form1.Caption :='Text'" bin ich klar gekommen.

Jetzt möchte mich mit If Then auseinandersetzten.Würdet ihr mir das erklären wie man das richtig schreibt?Also ich hab mor das so vorogestellt-

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Caption :='Test Test'; // Gang normales Caption Funktion

if Form1.caption :='Test Test' then Label1.Caption :='Label hier'; 
end;

end.


Ich weiss nicht wie man das richtig schreibt. Erklärts mir kurz.

Hertherzlichen Dank für die Aufmerksamkeit.

Moderiert von user profile iconPeter Lustig: Verzierungen im Titel entfernt
Moderiert von user profile iconPeter Lustig: Topic aus Sonstiges verschoben am Sa 26.06.2004 um 15:12
neodeus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 51

WinXp
D7 Ent. (Unternehmens Lizenzs von Vaters Comp. )
BeitragVerfasst: Sa 26.06.04 14:07 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);  
begin  
Form1.Caption :='Test Test'; // Gang normales Caption Funktion  
 
if Form1.caption = 'Test Test' then Label1.Caption :='Label hier'; 
  
end;
end.


die delphi hilfe gibt sehr viele beispiele zu den kontrollstrukturen !
schau sie dir mal an.
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Sa 26.06.04 14:09 
Der Unterschied liegt in := und = .

:= ist eine Zuweisung

= ist ein Vergleich

a := b + c; ist eine Zuweisung. Zuerst wird b und c zusammenadiert, dann a zugewiesen.

a = b ist ein Vergleich. Hier werden a und b verglichen und es kommt ein True oder False raus.

Für if then brauchst du ein Vergleich, also kein :=, sondern nur =.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);  
begin  
Form1.Caption := 'Test Test'; // Gang normales Caption Funktion  
 
if Form1.caption = 'Test Test' then Label1.Caption := 'Label hier';   
end;

_________________
Gruß
Martin
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 26.06.04 14:12 
Hallo, Marat!

Bitte lasse demnächst die Verzierungen im Titel weg. Sie sind hier im Forum unüblich.

Grüße
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Marat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 25



BeitragVerfasst: Sa 26.06.04 14:51 
Danke Martin für die AUsführliche Antwort!
Jetzt verstehe ich auch Then und If!Danke nochmal.Aber jetzt taucht bei mir eine andere Frage auf-

Ich kann entweder die Action mit IF und THEN durcführen -

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Caption :='Test Test';

if Form1.caption = 'Test Test' then Label1.Caption :='Kjah'
end;

end.


Ich kann jedoch das selbe Ergebniss ohne if und then erziehlen -

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Caption :='Test Test';

Label1.Caption :='KJah';
end;

end.



Also- Welches ERGEBNISS kann ich mit IF und THEN Erreichen was ich mit ganz normalen ding da (siehe oben) nicht erreiche?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 26.06.04 15:12 
Hallo!

Obiges Beispiel ergibt nur deshalb mit und ohne IF das gleiche Ergebnis, weil Du ja das Caption von Form1 auf "Test Test" setzt und dann mit IF überprüfst, ob es auch wirklich "Test Test". Klar, dass das immer so ist, weil Du es ja vorher gesetzt hast.

MfG
Peter

P.S.: In den Tutorials gibt es auch eines zu IF-THEN-ELSE.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Marat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 25



BeitragVerfasst: Sa 26.06.04 15:25 
Ich habs nicht ganz verstanden. :(
Martin77
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 282

XP Prof
D6 Prof, D7 Personal, D7 Enterprise, D8 personal
BeitragVerfasst: Sa 26.06.04 15:29 
Ersetze mal folgendes:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);  
begin  
Form1.Caption := 'Test Test'; // Gang normales Caption Funktion  

....
end;

durch
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);  
begin  
Form1.Caption := 'Test Test II'; // Gang normales Caption Funktion  

....
end;


If ist eine Abfrage, du fragst in deinem beispiel ob ob die Caption Test Test ist. Wenn Du anstelle von der Caption ein EditFeld verwendest, könntest du zB. abfragen ob eine Benutzereingabe gültig ist (z.B. ein passwort)


Martin
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 26.06.04 15:29 
Aaaaaaalso, Dein Code besteht ja aus diesen beiden Zeilen:
ausblenden Delphi-Quelltext
1:
2:
3:
Form1.Caption :='Test Test';

if Form1.caption = 'Test Test' then Label1.Caption :='Kjah'


In er ersten Zeile sorgst Du dafür, dass Form1 den Titel "Test Test" hast. In der zweiten Zeile prüfst Du, ob Form1 den Titel "Test Test" hat, um, falls dem so ist, das Caption von Label1 entsprechend zu setzen.
ABER: Dadurch, dass Zeile 1 den Titel auf "Test Test" setzt, ist die Bedingung in Zeile 2 (Ob der Titel "Test Test" ist) ja immer erfüllt.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Sa 26.06.04 15:32 
Mach es mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);  
begin  
Form1.Caption :='Test Test';  

 
if Form1.Caption = 'Mama ist die Beste' then Label1.Caption :='Kjah'  
end;

_________________
Gruß
Martin
Marat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 25



BeitragVerfasst: Sa 26.06.04 16:45 
Aaachsooo!Sorry ist leicht!Also bei direktem Label1.Caption :='Test' wird es immer gleich gewechselt und beim If then muss erst die bedinnung stimmen.Yap!Danke.

Geht mal hier drauf der in Mathe das Erweitern kann ^^

Moderiert von user profile iconPeter Lustig: URL-Tag repariert