Autor Beitrag
bonanza
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 11:54 
Hi,
ich wollte ein Quiz programmieren und dem Benutzer zum antworten nur 25 Sek. Zeit geben. Nun wollte ich dies mit einer ProgressBar dem Benutzer zeigen, also wie lange er zeit hat.
meine frage:
wie kann ich die ProgressBar so einstellen, dass das Max bei 25 sek. liegt und er jede Sek. eins weiter geht ?

danke schonmal im voraus
bonanza


Moderiert von user profile iconUGrohne: Topic aus Sonstiges verschoben am So 18.12.2005 um 03:07
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 17.12.05 12:12 
zbs. So

ausblenden 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:
var
  Form1: TForm1;
  Zaehler:Integer;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled:=True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Inc(Zaehler);
  Timer1.Interval:=1000;
  ProgressBar1.StepIt;
  ProgressBar1.Step:=4;
  if Zaehler = 25 then Timer1.Enabled:=False;
  if Zaehler = 25 then Caption:='Zeit vorbei';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Enabled:=False;
end;
MadDoctor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 88

Win XP Pro
Delphie 2005
BeitragVerfasst: Sa 17.12.05 12:16 
Mach das doch mit nem Timer

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
{...}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ProgressBar1.Position := ProgressBar1.Position +1;

  If ProgressBar1.Position = 100 then
  Timer1.Interval := 0;
end;
{...}


Du kannst auch noch mit den einstellungen "Min" und "Max" unter "Verschiedenes" bei der ProgressBar rumspielen !

[Edit]
Och Menno, zu langsam !
[/Edit]

_________________
Grüße an alle Grevener [NRW]
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 12:24 
Hi,
erstmal danke..

aber es kommt immer der fehler beim compilieren:
"[Error] progressbar.pas(33): Undeclared identifier: 'Timer1Timer'"

natürlich hab ich auch nen timer erstellt und ne progressbar und nen button...woran liegt es denn ?
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Sa 17.12.05 12:27 
Hallo!

Wurdest du nicht schon in mehreren anderen Threads darauf hingewiesen dir das da mal durchzulesen? Crashkurs Delphi ;)

Um den fehler zu finden braucht man schon ein bisschen mehr code :D ;)

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

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 17.12.05 12:28 
vllt liegts daran, dass du die timer kompente, zufinden unter system, nicht auf deinem form platziert hast :roll:
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 12:31 
ich hab mir diesen Crashkurs schon durchgelesen...danke

ich habe den timer erstellt....(s.o.)
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Sa 17.12.05 12:32 
user profile iconNoTVerYEvilPzYchO hat folgendes geschrieben:
vllt liegts daran, dass du die timer kompente, zufinden unter system, nicht auf deinem form platziert hast :roll:


glaub ich weniger

user profile iconbonanza hat folgendes geschrieben:
natürlich hab ich auch nen timer erstellt und ne progressbar und nen button...


;)

ich denke eher an Copy & Paste ohne mal delphi die procedure mit nem doppelclick auf den timer erstellen zu lassen -_-

EDIT: @Bonanza: dann hast du ihn wohl schnell überflogen :P


Zuletzt bearbeitet von Born-to-Frag am Sa 17.12.05 12:33, insgesamt 1-mal bearbeitet
MadDoctor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 88

Win XP Pro
Delphie 2005
BeitragVerfasst: Sa 17.12.05 12:32 
könntest du uns evtl mal deinen code zeigen ?
oder hast du den von Blackheart666 direkt übernommen ?

_________________
Grüße an alle Grevener [NRW]
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 12:37 
user profile iconBorn-to-Frag hat folgendes geschrieben:
user profile iconNoTVerYEvilPzYchO hat folgendes geschrieben:
vllt liegts daran, dass du die timer kompente, zufinden unter system, nicht auf deinem form platziert hast :roll:


glaub ich weniger

user profile iconbonanza hat folgendes geschrieben:
natürlich hab ich auch nen timer erstellt und ne progressbar und nen button...


;)

ich denke eher an Copy & Paste ohne mal delphi die procedure mit nem doppelclick auf den timer erstellen zu lassen -_-

EDIT: @Bonanza: dann hast du ihn wohl schnell überflogen :P


^^
Ich hatte Die Proceduren manuell in den code unter type eingefügt (ohne tippfehler)...jetzt habe ich mal ein ganz neues projekt gemacht und per doppelklick erstellt...dann hats geklappt

danke
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Sa 17.12.05 12:39 
user profile iconbonanza hat folgendes geschrieben:
user profile iconBorn-to-Frag hat folgendes geschrieben:
user profile iconNoTVerYEvilPzYchO hat folgendes geschrieben:
vllt liegts daran, dass du die timer kompente, zufinden unter system, nicht auf deinem form platziert hast :roll:


glaub ich weniger

user profile iconbonanza hat folgendes geschrieben:
natürlich hab ich auch nen timer erstellt und ne progressbar und nen button...


;)

ich denke eher an Copy & Paste ohne mal delphi die procedure mit nem doppelclick auf den timer erstellen zu lassen -_-

EDIT: @Bonanza: dann hast du ihn wohl schnell überflogen :P


^^
Ich hatte Die Proceduren manuell in den code unter type eingefügt (ohne tippfehler)...jetzt habe ich mal ein ganz neues projekt gemacht und per doppelklick erstellt...dann hats geklappt

danke


Und du hättest die Procedure trotzem doch beim Timer einfügen müssen.. naja nächstes mal nich immer Copy & Paste ;) -.-
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 12:49 
hab allerdings noch eine frage...wenn die zeit abgelaufen ist...wie sage ich ihm, dass er diret die procedure TForm2.Button1Click(Sender: TObject); aufrufen soll?


und jetzt sind die blauen streifen nicht am ende, wenn die 25 sek. abgelaufen sind sondern bleiben in der mitte stehen, weil die bar zu gross ist denke ich mal...kann man die grösse durch das programm irgendwie optimal anpassen lassen?
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 17.12.05 13:10 
Das hatt mit der Größe nix zu Tun, dann hast Du bestimmt eine andere Zeit oder einen Anderen Step gewählt die Progressbar geht bis 100 / 25 = 4 - Also Du musst 100 durch deine Zeit teilen dann hast Du die Stepanzahl.
Dann müsste es klappen.
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 13:24 
Ich habe es auf 4 stehen aber jetzt beginnt der nach ein paar sek mit einem neuen / leeren bar und macht dann da nur 2 blaue balken dann ist ende....
was mache ich falsch?

...und mit der prozedur ... wie rufe ich die auf? ohne die in eine neue zu schreiben ?
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 22:47 
Das ist jetzt mein kompletter Code...


allerdings kommt dieser Fehler 2 mal "[Error] Unit2.pas(43): '(' expected but ';' found" in den mit den Pfeilen markieren Zeilen...woran liegt das?
und warum klappt das mit der PRogressBar nicht, dass er das nur einmal füllt ?
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:
begin

  If (form2.T2Antwort.Text = Antworten[button]) then
  begin
    showmessage ('Ihre Antwort ist korrekt');
    Geld := Geld + Betrag;
    close;  //<---
  end
   else begin
     showmessage ('Ihre Anwort ist falsch');
     Geld := Geld - Betrag;
     close; //<---
   end;

end;


procedure TForm2.Button1Click(Sender: TObject);
begin
 Unit2haupt;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  Inc(Zaehler);
  Timer1.Interval:=1000;
  ProgressBar1.StepIt;
  ProgressBar1.Step:=4;
  if Zaehler = 25 then Timer1.Enabled:=False;
  if Zaehler = 25 then Caption:='Zeit vorbei';
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=true;
end;


danke schonmal im voraus

bonanza
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Sa 17.12.05 22:47 
user profile iconbonanza hat folgendes geschrieben:
Das ist jetzt mein kompletter Code...


allerdings kommt dieser Fehler 2 mal "[Error] Unit2.pas(43): '(' expected but ';' found" in den mit den Pfeilen markieren Zeilen...woran liegt das?
und warum klappt das mit der PRogressBar nicht, dass er das nur einmal füllt ?
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:
procedure Unit2haupt;
begin
  If (form2.T2Antwort.Text = Antworten[button]) then
  begin
    showmessage ('Ihre Antwort ist korrekt');
    Geld := Geld + Betrag;
    close;  //<---
  end
   else begin
     showmessage ('Ihre Anwort ist falsch');
     Geld := Geld - Betrag;
     close; //<---
   end;

end;


procedure TForm2.Button1Click(Sender: TObject);
begin
 Unit2haupt;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  Inc(Zaehler);
  Timer1.Interval:=1000;
  ProgressBar1.StepIt;
  ProgressBar1.Step:=4;
  if Zaehler = 25 then Timer1.Enabled:=False;
  if Zaehler = 25 then Caption:='Zeit vorbei';
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=true;
end;


danke schonmal im voraus

bonanza
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 18.12.05 02:18 
Das war doch nicht der komplette Code
Die Procedure hast Du warscheinlich nicht Deklariert.
Kann man ja leider in deinem Anhang nicht sehen.
Das mit dem Timer dürfte Dir eigentlich klar sein, Du rufst ihn nur einmal in FormCreate auf und nach 25s ist Schluss.
Du musst den Timer dann erneut aufrufen wenn Du Ihn brauchst.

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:
 type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Unit2haupt; {Nicht deklariert ?} 
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}
procedure TForm2.Unit2haupt; {TForm2.}
begin
  If (form2.T2Antwort.Text = Antworten[button]) then
  begin
    showmessage ('Ihre Antwort ist korrekt');
    Geld := Geld + Betrag;
    Form2.Close;  //<---
  end
   else begin
     showmessage ('Ihre Anwort ist falsch');
     Geld := Geld - Betrag;
     Form2.Close; //<---
  end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  Unit2haupt;
end;
end.
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: So 18.12.05 10:33 
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:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    T2Frage: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    T2Antwort: TEdit;
    Button1: TButton;
    Timer1: TTimer;
    ProgressBar1: TProgressBar;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  zaehler: integer;
implementation

uses Unit1;

{$R *.dfm}
procedure Unit2haupt;
begin

  If (form2.T2Antwort.Text = Antworten[button]) then
  begin
    showmessage ('Ihre Antwort ist korrekt');
    Geld := Geld + Betrag;
    close;
  end
   else begin
     showmessage ('Ihre Anwort ist falsch');
     Geld := Geld - Betrag;
     close;
   end;

end;


procedure TForm2.Button1Click(Sender: TObject);
begin
 Unit2haupt;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  Inc(Zaehler);
  Timer1.Interval:=1000;
  ProgressBar1.StepIt;
  ProgressBar1.Step:=4;
  if Zaehler = 25 then Timer1.Enabled:=False;
  if Zaehler = 25 then Caption:='Zeit vorbei';
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=true;
end;

end.


Hier ist jetzt der komplette code...Danke schonmal
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 18.12.05 10:46 
Ich habs Mir doch gedacht Du hast die procedure nicht Deklariert, genauso Antworten[button], Geld, Betrag .
Du solltest Dir den Crashkurs nochmal etwas intensiver anschauen.
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: So 18.12.05 13:06 
Danke...habe das problem gefunden und gelöst.