Autor Beitrag
tobkin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Mo 07.04.08 12:39 
Servus,
ich bin relativ neu in der Delphiwelt, habe aber schon ein kleines Problem.

Es gibt ja unter Delphi2007 die funktion WeekOfYear.

Aber ich scheitere daran diese zu benutzen...
Wie genau muss die Syntax aussehen, damit ich die KW zurückgegeben bekomme.

Hier meine Syntax:

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:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, dateutils, IdBaseComponent, IdDateTimeStamp;
type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
var
  Form1: TForm1;
   KW:integer;
implementation
{$R *.dfm}
procedure AddTTimeStamp(ATimeStamp: TIdDateTimeStamp);
begin
  KW:=ATimeStamp.WeekOfYear;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  Zahl : string;
begin
  Zahl:=copy(Edit1.Text,5,2);
 if KW<>strtoint(Zahl) then
  showmessage  ('Bauteilalter kontrollieren')
 else
  Label1.Caption:=Zahl;
end;
end.



Diese fúnktionert aber leider nicht....
Ich danke Euch schon im vorraus.

Gruß
Tobias

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Kri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 118



BeitragVerfasst: Mo 07.04.08 13:27 
Hi,

ich hatte das so gemacht um die KW zu ermitteln:

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:
function WeekOfYear(D : TDateTime) : integer;
var
 aDate        : Integer;
 MinDate      : tDateTime;
 MaxDate      : tDateTime;
 Day, Month, Year : Word;
 FirstDate    : Integer;
begin
 aDate := Trunc(D);
 MinDate := EncodeDate(1900, 1, 1);
 MaxDate := EncodeDate(3999, 12, 31);
 if (aDate < MinDate) or (aDate > MaxDate) then
 begin
  Result := 0;
  exit;
 end;

aDate  := aDate  + 3 - ((5 + DayOfWeek(aDate)) MOD 7);
DecodeDate(aDate, Year, Month, Day);
FirstDate := Trunc(EncodeDate(Year, 1, 1));

Result := 1 + (aDate - FirstDate) DIV 7;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=IntToStr(weekofyear(now));
end;
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Mo 07.04.08 13:35 
Wie wär's so:

1) Unit DateUtils einbinden (Uses)
und dann diese Funktion benutzen:

WeekOfTheYear(now); // oder eben die TDateTime-Var von dir

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
tobkin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Mo 07.04.08 13:42 
DANKE !!!

Die letzte Version habe ich nun genommen und es funktioniert auf anhieb!

Vielen Dank Euch allen nochmal.

Gruß Tobias