Autor Beitrag
ElTonno
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

XP, Win 7, Ubuntu
Delphi 2007 Enterprise
BeitragVerfasst: Do 06.08.09 02:45 
Hi Leute,

Ich hab folgendes Problem.
Ich möchte von 2 MaskEdit Feldern die Datumswerte inkrementieren, so das ich ein Startdatum eingebe und ein Enddatum.
Die Datumsangaben zwischen diesen beiden Werten sollen in eine ListBox geschrieben werden.
Vllt kann mir jemand auf die sprünge helfen warum es nich geht. THX
Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
uses dateutils

var
  Form1: TForm1;
  Startdatum, Endedatum : TDateTime;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Startdatum:= StrToDate(Dstart.Text);
  Endedatum := StrToDate(Dende.Text);
  while Start > Ende do begin
    ListBox1.Items.Add(DateToStr(Startdatum));
    IncDay(Startdatum);
  end;
end;
end.


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Andreas Schilling
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128
Erhaltene Danke: 1

WIN XP, WIN 7
Delphi 5 Ent, Delphi 2007 Pro, XE4
BeitragVerfasst: Do 06.08.09 07:01 
Ich weis zwar nicht wo du "Start" und "Ende" herholst (soll sicher Startdatum und Enddatum sein) und was nun eigentlich nicht geht, aber ich gehe davon aus das "Start" kleiner als "Ende" ist. Also wäre es richtig
ausblenden Delphi-Quelltext
1:
  while Startdatum < Endedatum					
NetSpider
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 123

Windows XP Pro
Delphi 7 Enterprise
BeitragVerfasst: Do 06.08.09 11:01 
Hier eine Loesung ganz ohne DateUtils:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  StartDate, EndDate: Cardinal;

procedure ShowDates;
begin
  StartDate := Trunc(StrToDate(MaskEdit1.Text)) (*+1*);
  EndDate := Trunc(StrToDate(MaskEdit2.Text)) (*-1*);
  while StartDate <= EndDate do begin
    ListBox1.Items.Add(DateToStr(StartDate));
    Inc(StartDate);
  end;
end;


Trunc schneidet den Komma-Wert des Datums ab (sollte einer vorhanden sein) und schreibt den Wert nach StartDate und EndDate. Dann wird die while Schleife durchlaufen. Hier werden sowohl Anfangs- als auch End-Datum mit ausgegeben. (* Kommentar entfernen um Start- und End-Datum nicht mit auszugeben *)

Lg,

Alex

_________________
Wer in die Fußstapfen anderer tritt hinterlässt keine eigenen Spuren!
ElTonno Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

XP, Win 7, Ubuntu
Delphi 2007 Enterprise
BeitragVerfasst: Fr 07.08.09 18:19 
voll cool. fettes thx für die schnelle hilfe von dir. bin noch anfänger, also nochmals vielen dank für die hilfestellung.