Autor Beitrag
SpaghettiCodix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: Do 27.09.07 15:48 
Hallöchen,

wer kann mir helfen? Ich möchte ein Datum mit Monaten hochrechnen, also zum Beispiel
zum 1.01.2001 48 Monate zuzählen.

Wenn ich mit DecodeDate das Datum in Jahre, Monate und Tage aufteile, kann ich nicht einfach zur Variablen Monat die Zahl 48 addieren, weil es sonst beim Encodieren eine Fehlermeldung gibt.
Ich habe Delphi 2005.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 27.09.07 15:56 
Dafür gibt es Funktionen wie z.B. incMonth

_________________
We are, we were and will not be.
SpaghettiCodix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: Do 27.09.07 16:08 
Titel: Danke Gausi :-)
Danke Gausi, bin etwas unbeholfen mit der Delphi 2005 Hilfe.
Hatte vorher Delphi 2. Dort war es mit der Hilfe irgendwie einfacher.

Aber gut, da muß ich jetzt nicht selber so eine Funktion schreiben.
Nicht, daß es mich nicht reizen würde, aber da geht viel Zeit verloren.

Nochmals vielen Dank für Deinen Hinweis.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 27.09.07 16:17 
So sieht die IncMonth()-Funktion aus. Sei froh, dass du sie nicht selber schreiben musst ;-):

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:
function IncMonth(const DateTime: TDateTime; NumberOfMonths: Integer): TDateTime;
var
  Year, Month, Day: Word;
begin
  DecodeDate(DateTime, Year, Month, Day);
  IncAMonth(Year, Month, Day, NumberOfMonths);
  Result := EncodeDate(Year, Month, Day);
  ReplaceTime(Result, DateTime);
end;

procedure IncAMonth(var Year, Month, Day: Word; NumberOfMonths: Integer = 1);
var
  DayTable: PDayTable;
  Sign: Integer;
begin
  if NumberOfMonths >= 0 then Sign := 1 else Sign := -1;
  Year := Year + (NumberOfMonths div 12);
  NumberOfMonths := NumberOfMonths mod 12;
  Inc(Month, NumberOfMonths);
  if Word(Month-1) > 11 then    // if Month <= 0, word(Month-1) > 11)
  begin
    Inc(Year, Sign);
    Inc(Month, -12 * Sign);
  end;
  DayTable := @MonthDays[IsLeapYear(Year)];
  if Day > DayTable^[Month] then Day := DayTable^[Month];
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
SpaghettiCodix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: Fr 28.09.07 21:54 
user profile iconGTA-Place hat folgendes geschrieben:
So sieht die IncMonth()-Funktion aus. Sei froh, dass du sie nicht selber schreiben musst ;-):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure IncAMonth(var Year, Month, Day: Word; NumberOfMonths: Integer = 1);
var
  DayTable: PDayTable; // <- was ist denn das fürn Zeiger?
  .....
begin


Na gottseidank. Ich hatte auf meinem alten Rechner mal eine Funktion, die fast fehlerfrei
funzte. Allerdings mit vielen 'If' Bedingungen und ehrlich, ich würde diese Funktion keinem Delphianer zeigen, ohne rot zu werden.

Kannst Du mir sagen, was das für ein Zeiger ist in der Funktion IncAMonth?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 29.09.07 08:40 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
type
  PDayTable = ^TDayTable;
  TDayTable = array[1..12of Word;

const
  MonthDays: array [Boolean] of TDayTable =
    ((312831303130313130313031),
     (312931303130313130313031));

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
SpaghettiCodix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: Mi 03.10.07 10:51 
user profile iconGTA-Place hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
type
  PDayTable = ^TDayTable;
  TDayTable = array[1..12of Word;

const
  MonthDays: array [Boolean] of TDayTable =
    ((312831303130313130313031),
     (312931303130313130313031));


Saubere Sache. Danke GTA-Place.

Wenn ich mir vor Augen halte, was ich mir für gedankliche Verrenkungen mache, um eine Funktion hinzubekommen. Wenn Du nun selber nicht der Entwickler dieser Funktion bist, wie kommst Du an den Quelltext der vordefinierten Funktionen in Delphi?
Kann man den Quelltext irgendwo nachlesen? Ich hoffe, daß ich Dir mit meiner Fragerei nicht auf den Keks gehe :-)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 03.10.07 12:18 
Bei den Pro-Versionen von Delphi sind die Sources dabei.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Arne Danikowski
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 194



BeitragVerfasst: Mi 03.10.07 20:18 
Kannst aber auch einfach das Datum + Tage rechnen. Wenn man das nur einmal braucht reicht das häufig auch und der Quellcode wird kleiner.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Var tag1,tag2:tday

begin
//aktuelles Datum in Variable kann auch ein anderes Datum sein
tag1:=now;
// tag1:='01.01.2001'
//Datum + 48 Monate (1461 Tage) + 1 Tag wegen Schaltjahr 
tag2:=(tag1+1461)
//Ausgabe in zb. ein Edit Feld
edit1.text:=DateToStr (tag2);

end:


Zuletzt bearbeitet von Arne Danikowski am Do 04.10.07 09:16, insgesamt 1-mal bearbeitet
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mi 03.10.07 23:42 
user profile iconSpaghettiCodix hat folgendes geschrieben:
..wie kommst Du an den Quelltext der vordefinierten Funktionen in Delphi?...


Einfach durch nachdenken und lernen. Das bezieht sich allerdings auf die Logik der "vordefinierten Funktionen". 8) Ansonsten eben gucken, wo das geklaut werden kann. :mrgreen:

_________________
Gruß
Hansa