Autor Beitrag
Baltus
Hält's aus hier
Beiträge: 12

Win XP
Delphi 5
BeitragVerfasst: Di 22.08.06 16:37 
Hallo,
ich muss bis Donnerstag eine Anwendung geschrieben haben die, wenn ich auf den Button klicke die Farbe in blau und bei nochmaligem klicken in rot ändert. Soviel hab ich schon geschrieben:
:arrow:
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:
50:
51:
52:
53:
54:
unit mFarben3;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFarben3 = class(TForm)
    Bt_one: TButton;
    procedure Bt_oneClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Farben3: TFarben3;

implementation

{$R *.DFM}

procedure TFarben3.Bt_oneClick(Sender: TObject);

begin

if Farben3.color = clred

then {begin

Farben3.color := clblue;

Bt_one.caption := 'Erröten!';

Farben3.caption := 'Ich mache jetzt BLAU!';

end}


else {begin

Farben3.color := clred;

Bt_one.caption := 'Ich will BLAU machen!';

Farben3.caption := 'Ich schäme mich...';

end}
;

end;

end.


Soweit so gut aber wenn ich jetzt auf den Button klicke ändert das Fenster seine Farbe nicht wie vorgesehen.
Ich glaub der Fehler liegt in den {}, kann ja sein dass welche fehlen oder so. :?:
Danke schonmal im vorraus, für euere Hilfe. :D


Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 24.08.2006 um 18:42
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Di 22.08.06 16:40 
Erstma :welcome: herzlich willkommen im DF!

Bist wohl noch an cpp gewöhnt, was ;)

In Delphi müsste es so aussehen:

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:
unit mFarben3;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFarben3 = class(TForm)
    Bt_one: TButton;
    procedure Bt_oneClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Farben3: TFarben3;

implementation

{$R *.DFM}

procedure TFarben3.Bt_oneClick(Sender: TObject);

begin

if Farben3.color = clred then 
begin
  Farben3.color := clblue;
  Bt_one.caption := 'Erröten!';
  Farben3.caption := 'Ich mache jetzt BLAU!';
end else 
begin
  Farben3.color := clred;
  Bt_one.caption := 'Ich will BLAU machen!';
  Farben3.caption := 'Ich schäme mich...';
end;

end;

end.
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Di 22.08.06 16:50 
Moin...
Also ich denke mal dein Button verweigert den Dienst Weil beim Start dein Form.color=clBtnFace ist.

eine kleine Zeile behebt das Prob.

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:
50:
51:
52:
53:
54:
unit mFarben3;  

 
interface  

 
uses  
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  
  StdCtrls;  

 
type  
  TFarben3 = class(TForm)  
    Bt_one: TButton;  
    procedure Bt_oneClick(Sender: TObject);  
  private  
    { Private-Deklarationen }  
  public  
    { Public-Deklarationen }  
  end;  

 
var  
  Farben3: TFarben3;  

 
implementation  

 
{$R *.DFM}  

 
procedure TFarben3.Bt_oneClick(Sender: TObject);  
begin  

If Farben3.Color=clBtnFace then Farben3.Color:=clred; 

if Farben3.color = clred then   
begin  
  Farben3.color := clblue;  
  Bt_one.caption := 'Erröten!';  
  Farben3.caption := 'Ich mache jetzt BLAU!';  
end else   
begin  
  Farben3.color := clred;  
  Bt_one.caption := 'Ich will BLAU machen!';  
  Farben3.caption := 'Ich schäme mich...';  
end;  

 
end;  

 
end.

gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
Baltus Threadstarter
Hält's aus hier
Beiträge: 12

Win XP
Delphi 5
BeitragVerfasst: Di 22.08.06 17:08 
Ja super!!! :dance2:
War wirklich mein überhaupt zweites Projekt. :nixweiss:
DANKE, jetzt gehts :party:
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 16:28 
ich bräuchte jetzt das ganze mit vier farben.

rot blau gelb und grün

danke für die hilfe im vorraus
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Do 24.08.06 16:35 
wie ...wenn du auf den Button klickst isses erst rot zweiter klick blau dritter klick grün usw.
oder wie????

da kommst du doch selber drauf :mahn:
gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 16:50 
nein eben nicht bin zu doof dafür^^
habs schon probiert der wechselt nur einmal die farbe und danach garnicht.
Ich hab kene ahnung wie ich das angehen muss(bin anfänger)
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Do 24.08.06 16:54 
mal so aus der hüfte geschossen...
beschäftige dich mit if then elseif.
gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 17:01 
mitr if und else hab ich ja probiert aber nach einem farbenwechsel istz ende banane
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 24.08.06 17:02 
Zeig mal, wie dus probiert hast.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 17:09 
mom bin grad auf ne idee gekommen wills mal probieren
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Do 24.08.06 17:09 
also bei mir gehts ....1 x if mit 4 x else if :lol:
gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 17:11 
hast du variablen eingesetzt?
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Do 24.08.06 17:13 
ja eine... Farbe: TColor
aber nur um schreibarbeit zu sparen

ein kleiner denkanstoss
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
Farbe:=Form1.Color;
if Farbe =clbtnFace then
 begin
  Form1.Color:=Clred
 end
 else if Farbe =clred then Form1.Color:=Clblue
...
...
...

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 17:16 
ganz oben ist ja der text für die 2 farben.
muss ich das nur erweitern oder ganz ändern?
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Do 24.08.06 17:19 
haste die änderung in meinem vorherigen post gesehen?

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 17:25 
ja gerade erst^^
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Do 24.08.06 17:34 
Und haste es jetzt :?: :wink2:

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
FiFtY
Hält's aus hier
Beiträge: 11


Delphi
BeitragVerfasst: Do 24.08.06 17:42 
ja die farben schon aber ich prügel mich egrade mit der caption des form1´s und des buttons
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Do 24.08.06 18:00 
Ok..hier kommt meine abgeänderte version:
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:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Farbe:TColor;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Farbe:=Form1.Color;
 case Farbe of
  clBtnFace: begin
              Button1.Caption:='Klick mich dann werde ich blau';
              Form1.Color:=Clred;
             end;
  clred:     begin
               Button1.Caption:='Klick mich dann werde ich gelb';
               Form1.Color:=Clblue;
              end;
  clblue:    begin
              Button1.Caption:='Klick mich dann werde ich grün ';
              Form1.Color:=clyellow;
             end;
  clyellow:  begin
              Button1.Caption:='Klick mich dann werde ich rot';
              Form1.Color:=clgreen;
             end;
  clgreen:   begin
              Button1.Caption:='Klick mich dann werde ich blau';
              Form1.Color:=clred;
             end;
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Farbe:=Form1.Color;
Button1.Caption:='Klick mich dann werde ich rot';
end;

end.

gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]