Autor Beitrag
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 30.03.06 18:48 
Moin!

Ich hätte da auch noch eine "Anregung": ;)
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:
const
  MinWert = 1;   // Startwert
  MaxWert = 2;   // Endwert
  Schritt = 0.1; // Schrittweite

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    Wert,              // aktueller Wert
    Aenderung: Single; // aktuelle Wertänderung
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// bei Programmstart ausführen
procedure TForm1.FormCreate(Sender: TObject);
begin
  Wert := MinWert; // Startwert übernehmen
  Aenderung := Schritt; // Schrittweite übernehmen
  Label1.Caption := FloatToStrF(Wert,ffFixed,2,1); // Ausgeben
end;

// Timer-Ereignis
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Wert := Wert +Aenderung; // Wert verändern
  if ( (Wert <= MinWert) or (Wert > MaxWert) ) then // ausserhalb der Grenzen?
    Aenderung := -Aenderung; // dann "andersrum" ändern ;-)
  Label1.Caption := FloatToStrF(Wert,ffFixed,2,1); // Ausgeben
end;

// Button Start/Stop
procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled := NOT Timer1.Enabled; // Timer-Zustand umschalten
end;

Und hier noch das DFM (mit F12 und dann Alt+F12 in den Textmodus schalten, ersetzen und mit Alt+F12 wieder zurück):
ausblenden volle Höhe 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:
object Form1: TForm1
  Left = 1094
  Top = 109
  Width = 137
  Height = 104
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 32
    Height = 13
    Caption = 'Label1'
  end
  object Button1: TButton
    Left = 16
    Top = 40
    Width = 75
    Height = 25
    Caption = '&Start/Stop'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Timer1: TTimer
    Enabled = False
    Interval = 250
    OnTimer = Timer1Timer
    Left = 80
    Top = 8
  end
end

cu
Narses
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Do 30.03.06 19:18 
Also mein rein theoretischer Ansatz ist eigentlich folgender:

Boolean ist ja entweder true oder false.
Jetzt hab ich überlegt das wenn der timer 2 erreicht hat boolean true wird einfach gesagt, und dann das runterzählen los geht... also if schnubbi:= true then...
Allerdings komm ich da nicht richtig weiter, also sag mir bitte wenigstens obs im Ansatz richtig ist bevor ich weiter in die richtung überlege ;)
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Do 30.03.06 19:20 
Jetzt verwirrste mich Narses... ;)
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Do 30.03.06 19:53 
user profile iconKunibert der Kleine hat folgendes geschrieben:
also sag mir bitte wenigstens obs im Ansatz richtig ist bevor ich weiter in die richtung überlege ;)


der ansatz is supi :) (zumindest sieht meiner genauso aus ;) )
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Do 30.03.06 20:08 
OK..
Im moment versteh ich noch nich ganz wie ich die Bedingung für boolean=true definiere.
Also das es true wird wenn es "2" ist....

Btw: Gibt es für solche sachen eigentlich eine gute web hilfe außer Foren bzw. delphi hilfe?
Also wie de.selfhtml.org/ für html.
Bin bis jetzt unfündig geblieben
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Do 30.03.06 20:15 
keine ahnung...

also ich hab mir das so gedacht:

im timer wird erst zahl1 gesetzt,
dann wird der boolean-wert geprüft (über if)
ist er nicht erfüllt (=false), wird erst geprüft, ob die zahl kleiner als zwei ist.
ist sie das, wird 0,1 dazugezählt. ist sie es nicht (d.h. sie ist >=2), wird 0,1 abgezogen und der boolean-wert umgesetzt.
und wenn der booleanwert erfüllt ist (= else vom ersten if),
wird geprüft, ob die zahl größer ist, als 1. wenn ja, dann 0,1 abziehen, wenn nicht (d.h. sie ist <=1) wird wieder eins zugezählt und der boolean-wert umgesetzt...

und nu proggen ;)
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Do 30.03.06 21:16 
:cry:
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 30.03.06 21:52 
Moin!

user profile iconKunibert der Kleine hat folgendes geschrieben:
Jetzt verwirrste mich Narses... ;)

Was ist unklar? Haste´s denn ausprobiert? (einfach neues Projekt anlegen, das Formular über den Textumweg übernehmen und den Code passend einfügen)

cu
Narses
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Do 30.03.06 22:12 
Hier mal deine Überlegung mit zwei Timern.

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:
var
  Form1: TForm1;
  zahl:Real;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  zahl:=1;
  Label1.Caption:='1';
  Timer1.Enabled:=False;
  Timer2.Enabled:=False;
end;

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

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  zahl:=zahl+0.1;
  if zahl>2 then Timer1.Enabled:=False;
  if zahl>2 then Timer2.Enabled:=True;
  Label1.Caption:=FloatToStr(zahl);
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  zahl:=zahl-0.1;
  if zahl<1.1 then Timer1.Enabled:=True;
  if zahl<1.1 then Timer2.Enabled:=False;
  Label1.Caption:=FloatToStr(zahl);
end;


Oder zb. so Mit Boolean

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:
var
  Form1: TForm1;
  HochRunter:Boolean;
  zahl:Real;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  zahl:=1;
  Label1.Caption:='1.0';
  HochRunter:=True;
  Timer1.Enabled:=False;
end;

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

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if HochRunter = True then zahl:=zahl+0.1
  else
  zahl:=zahl-0.1;

  if zahl> 2 then HochRunter:=False;

  if zahl< 1.1 then HochRunter:=True;
  Label1.Caption:=FloatToStr(zahl);
end;
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 31.03.06 12:13 
:!: :!:
so ähnlich hab ich das auch gemacht weil mit dem boolean Kram bin ich nicht kalr gekommen
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 31.03.06 13:39 
womit bist du denn nicht klar gekommen?
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 31.03.06 13:42 
Glaub das Prinzip von boolean will mir einfach nicht in den Kopf...
Denke auch das die lösung mit 2 Timern einfacher ist.
Allerdings hört der bei 2.1 auf und zählt nich runter bei mir.... ich probier noch bisschen rum
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 31.03.06 13:49 
hmm... was ist an boolean so schwer zu verstehen?

deklariert wird

ausblenden Delphi-Quelltext
1:
meinevariable : boolean;					


und die kannst du dann auf true oder false setzen:

ausblenden Delphi-Quelltext
1:
2:
meinevariable := true;
meinevariable := false;


und in ner if-anweisung kannst du sie prüfen mit

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if meinevariable then
...
if not meinevariable then
...


oder etwas länger:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if meinevariable = true then
...
if meinevariable = false then
...
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 31.03.06 13:52 
Ich versteh einfach nicht was "meineVariable" in dem Fall ist.
Also wie weist man der denn was zu?
Wann ist sie wahr. wann falsch....
Kann gut sein das es voll einfach ist, aber bei mir klickts irgendwie net
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 31.03.06 13:58 
user profile iconKunibert der Kleine hat folgendes geschrieben:
Ich versteh einfach nicht was "meineVariable" in dem Fall ist.


ein wahrheitswert.
der kann nur zwei verschiedene werte annehmen: true (wahr) und false (falsch)

user profile iconKunibert der Kleine hat folgendes geschrieben:
Also wie weist man der denn was zu?


genau wie du jeder anderen variable etwas zuweist. wie ich oben bereits schrieb

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var meininteger : integer;
    meinstring : string;
    meinboolean : boolean;
begin
  meininteger := 5;
  meinstring := 'hallo';
  meinboolean := true;
end;


user profile iconKunibert der Kleine hat folgendes geschrieben:
Wann ist sie wahr. wann falsch....


sie ist wahr, wenn du sie auf wahr gesetzt hast, und falsch wenn du sie auf falsch gesetzt hast...

user profile iconKunibert der Kleine hat folgendes geschrieben:
Kann gut sein das es voll einfach ist, aber bei mir klickts irgendwie net


für dein beispiel würde das bedeuten, dass du dir erstmal gedanken machen musst, wie's dir am besten gefällt.
soll das programm raufzählen, ist der wert WAHR, soll er runterzählen FALSCH, oder andersrum.
dementsprechend setzt du sie; zu beginn, bevor du den timer startest und natürlich immer dann, wenn die richtung wechselt, also wenn dein zähler die 2 erreicht hat, oder wenn er wieder bei 1 angekommen ist.
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 31.03.06 14:02 
Das mit dem false/true etc ist mir alles klar...
aber bedeutet das nun dass bei diesem beispiel,

ausblenden Delphi-Quelltext
1:
2:
3:
  meininteger := 5;
  meinstring := 'hallo';
  meinboolean := true;


dass meinboolean true ist wenn meininteger '5' ist und meinstring 'hallo' ??
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 31.03.06 14:04 
nein, ist doch nirgendwo ne bedingung eingebaut...
wenn du verschiedene variablen untereinander setzt, sind die doch auch nicht voneinander abhängig.

stände da

if meininteger = 5 then
meinboolean = true;

dann wärs so...
aber sonst sinds nur einzelne anweisungen, die nacheinander ausgeführt werden...
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 31.03.06 14:09 
ahhhh ja ok, ich habs nu....
Ja ich weiss das da keine Bedingung eingebaut ist und das hat mich so verwirrt weil ich dachte das schon da die abhängigkeit entstehen würde...
aber habs nu verstanden...
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 31.03.06 14:11 
supi :) dann kann ich ja jetzt feierabend machen ;)
du kannst dir ja den quelltext von blackheart666 nochmal anschauen, der macht exakt das, was ich auch erzielen wollte... und ist gar nicht so kompliziert ;)
und bei fragen, weißt ja bescheid... :)
Kunibert der Kleine Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 31.03.06 14:13 
Ok klappt alles :)

Vielen lieben Dank....