Einzelnen Beitrag anzeigen

olaf

Registriert seit: 4. Mai 2009
Ort: Iserlohn
82 Beiträge
 
RAD-Studio 2009 Pro
 
#2

AW: D2007 Komponente zur Datum-/Zeiteingabe

  Alt 14. Sep 2010, 07:48
Hallo,

TMS benutze ich auch und bin damit zufrieden. Hier ein Funktion, die eine Eingabe von z.B 120684 in 12.06.1984 umwandelt. Habe ich geschrieben um auf true zu prüfen, weise result einfach das datum zu. Ist nicht sonderlich optimiert aber erfüllt den Zweck.

Delphi-Quellcode:
function TForm.datumpruefen: Boolean;
var
 gbtext, ja, mo, ta: string;
 jahr100g, jai, moi, p1, p2, tai: Integer;
begin
jahr100g :=YearOf(now)-2000;
gbtext := trim(Edit4.Text);
p1:=Posex('.',gbtext,1);

 If p1=0 then
 begin
  If Length(gbtext)<>6 then
  begin
  MessageDlg('Bei einer Eingabe des Geburtsdatums ohne Punkte(Trennzeichen), muß das Datum aus 6 Zahlen bestehen!', mtError, [mbOK], 0);
  Edit4.Clear;
  Abort;
  end;
 ta:=Copy(gbtext,0,2);
 mo:=Copy(gbtext,3,2);
 ja:=Copy(gbtext,5,2);
 end
 else
 begin
 ta:=Copy(gbtext,0,p1-1);
 p2:=Posex('.',gbtext,p1+1);
 mo:=Copy(gbtext,p1+1,p2-p1-1);
 ja:=Copy(gbtext,p2+1,10);
 end;

//tag

 if TryStrToInt(ta,tai)=true then
 tai:= StrToInt(ta)
 else
 begin
 MessageDlg('"'+ta +'" ist keine Tageszahl!''', mtError, [mbOK], 0);
 Abort;
 end;

 If (tai<1) or (tai>31) then
 begin
 MessageDlg('"'+ta+'" Die Tageszahl liegt außerhalb des Wertebereiches!', mtError, [mbOK], 0);
 Abort;
 end;

//monat

 if TryStrToInt(mo,moi)=true then
 moi:= StrToInt(mo)
 else
 begin
 MessageDlg('"'+mo +'" ist keine Monatszahlzahl!''', mtError, [mbOK], 0);
 Abort;
 end;

 If (moi<1) or (moi>12) then
 begin
 MessageDlg('"'+mo+'" Die Monatszahlzahl liegt außerhalb des Wertebereiches!', mtError, [mbOK], 0);
 Abort;
 end;

//jahr

 if TryStrToInt(ja,jai)=true then
 jai:= StrToInt(ja)
 else
 begin
 MessageDlg('"'+ja +'" ist keine Jahreszahlzahl!''', mtError, [mbOK], 0);
 Abort;
 end;

 If not((jai>=0) and (jai<=99)) and not((jai>=1850) and (jai<=2100)) then
 begin
 MessageDlg('"'+ja+'" Die Monatszahlzahl liegt außerhalb des Wertebereiches!', mtError, [mbOK], 0);
 Abort;
 end;


 If jai<=jahr100g then
 begin
  If jai<10 then
  Edit4. Text:=IntToStr(tai)+'.'+IntToStr(moi)+'.'+'200'+IntToStr(jai);

  If (jai>=10) and (jai<=jahr100g) then
  Edit4. Text:=IntToStr(tai)+'.'+IntToStr(moi)+'.'+'20'+IntToStr(jai);
 end;

 If (jai>jahr100g) and (jai<=99) then
 Edit4. Text:=IntToStr(tai)+'.'+IntToStr(moi)+'.'+'19'+IntToStr(jai);

result:= true;

end;
Olaf
  Mit Zitat antworten Zitat