Autor Beitrag
forcedbydelphi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Fr 05.11.10 11:28 
Hi Leute,
Thema:
wenn man auf ein Button klickt, soll am Zähler hochgezählt werden, also z.B. in 30 sek 100 mal geklickt, und das soll halt angezeigt werden.
Habt ihr tipps wie ich damit anfangen könnte?


Moderiert von user profile iconNarses: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Fr 05.11.2010 um 11:02
MaxWurzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 77
Erhaltene Danke: 10



BeitragVerfasst: Fr 05.11.10 11:35 
Eine globale Variable definieren und die dann bei jedem Klick um eins erhöhen.
ausblenden Delphi-Quelltext
1:
inc(globaleVariable);					

Für diesen Beitrag haben gedankt: forcedbydelphi
HouseGemacht
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18
Erhaltene Danke: 1

Win XP, Win7 Ultimate, Linux

BeitragVerfasst: Fr 05.11.10 11:39 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
var Zaehler, NeueZahl : Integer;
begin
  Zaehler:=StrToInt (Label1.Caption);
  NeueZahl:=Zaehler+1;
  Label1.Caption:= IntToStr(NeueZahl);
end;


Du braust daZU ein Label (labe1) dessen Caption 0 ist. Dann sollte es Funktionieren.

Für diesen Beitrag haben gedankt: forcedbydelphi
forcedbydelphi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Fr 05.11.10 11:44 
hab ich
ausblenden Delphi-Quelltext
1:
2:
icounter := icounter +1;
      Form1.Caption := 'Anzahl Klicks: ';


---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

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:
27:
28:
var
  Form1: TForm1;
  ibreite, ihoehe, icounter: integer;
  scounter: string// nur in dieser prozedur verwendet


implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
    randomize;  //Zufallsgenerator starten

end;

procedure TForm1.BtFangmichClick(Sender: TObject);
begin
      ibreite := Form1.Width - BtFangmich.Width; //entnimmt automatisch die breite vom Fenster
      ihoehe  := Form1.Height - BtFangmich.Height; // entnimmt automatisch die Hoehe vom Fenster
      BtFangmich.Left := random(ibreite - BtFangmich.Width); //Zufallsposition des Buttons in der Breite
      BtFangmich.Top  := random(ihoehe - BtFangmich.Height);  //Zufallsposition des Buttons in der Hoehe
      icounter := icounter +1;
      scounter := inttostr (icounter);
      Form1.Caption := 'Anzahl Klicks: '+scounter;
end;

end.

Danke leute, jetzt bräuchte ich eine Zeit die ab dem ersten Klick anfängt zu zählen (in sekunden)

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 05.11.10 11:56 
Siehe Delphi-Hilfe zum Thema SysUtils.Now oder GetTickCount

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)

Für diesen Beitrag haben gedankt: forcedbydelphi
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Fr 05.11.10 11:58 
Hey,

globale Variablen sind programmiertechnisch immer schlecht. Da du die nur auf deiner Form1 brauchst solltest du die auch im private-Bereich der TForm1 deklarieren.

MfG Bergmann.

p.s: wenn du Code posten willst benutz bitte die Delphi-Tags: <span class="inlineSyntax"><span class="codecomment">{PROTECTTAG2f26daab1a65acf12c70953a5558b7ae}</span></span>

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^

Für diesen Beitrag haben gedankt: forcedbydelphi
HouseGemacht
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18
Erhaltene Danke: 1

Win XP, Win7 Ultimate, Linux

BeitragVerfasst: Fr 05.11.10 12:17 
Du musst nur nen Timer nehmen, den Intervall auf 1000 setzen, Enabled auf False Setzen und Bei "Buttom1.Click" den Befehl Timer1.Enabled:=True ausführen lassen. So fürt er ab dem Klick jede Sekunde etwas aus. z.B. Die Caption eines Labes um 1 erhöhen.
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Fr 05.11.10 12:58 
Hey,

wenn er die Zeitanzeige live aktualisieren will ist das natürlich besser, aber wenn er einfach nur die Zeit ausrechnen will, dann ist GetTickCount die bessere Wahl. Da hat man es Millisekunden genau und der Rechner wird nicht so stark belastet (auch wenn es bei diesem Programm wohl kaum ins Gewicht fällt ^^). Wenn das ganze noch genauer werden soll kann man auch QueryPerformanceCounter nehmen.

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^