Autor Beitrag
Christoph Englmann
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Mo 16.04.07 14:20 
Hallo,

sorry für die saublöde Frage aber:
Wie ist die genaue Syntax für die Verwendung der 2. Version der StrToDateTime Funktion?
habs mit
ausblenden Delphi-Quelltext
1:
  StrToDateTime('070416','DDMMYY');					


versucht, aber leider krieg ich die Fehlermeldung:
')' erwartet aber ',' gefunden...


Hilfe....Danke
christoph
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mo 16.04.07 14:24 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Var x: TFormatSettings;
Begin
    x.DateSeparator := '|';
    StrToDateTime('12|31|23', x);
End;

Einfach die Kontexthilfe beachten oder F1 drücken ;)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Christoph Englmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Mo 16.04.07 14:43 
Erstmal danke...
(F1 und Kontexthilfe kann ich diesbezüglich schon auswendig... anscheinend bin ich einfach nur zu doof...)

habs jetzt folgendermaßen versucht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  Datums_Format :TformatSettings;

begin
  
        Datums_Format.LongDateFormat :='YYMMDD';
        Datum_Tabelle := StrToDateTime('070415',Datums_Format);

end;


leider krieg ich ne Zugriffsverletzung bei der zweiten Zeile....

christoph
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mo 16.04.07 15:05 
Nochmal die Hilfe genauer durchlesen! :mahn:
DelphiHilfe zu TFormatSettings:
So erstellen und verwenden Sie die von TFormatSettings definierte Thread-sichere Umgebung:

Definieren Sie eine Variable des Typs TFormatSettings.
Rufen Sie GetLocaleFormatSettings auf, um die Gebietsschema-Informationen in die TFormatSettings-Variable zu schreiben.
Übergeben Sie die TFormatSettings-Variable als letzen Parameter an die String-Formatierungsroutine.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
    GetLocaleFormatSettings(0, x);
    x.DateSeparator := '|';
    x.ShortDateFormat := 'YYMMDD';
    StrToDateTime('07|04|15', x);

Ich glaube aber nicht, dass du komplett ohne Seperator auskommst, aber den kannst du ja noch vorübergehend hinzufügen mit Insert oder ähnlichen Methoden.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Christoph Englmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Di 17.04.07 08:52 
Hallo,

erstmal wieder Danke....

hab jetzt folgendes versucht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
        GetLocaleFormatSettings(0,Datums_Format);
        Datums_Format.DateSeparator := '.';
        Datums_Format.ShortDateFormat :='YYMMDD';
        Datum_Tabelle := StrToDateTime('07.04.15',Datums_Format);



leider erscheint bei der letzten Zeile die Fehlermeldung:
'07.04.15' ist kein gültiges Datumsformat..

(habs auch schon mit YY.MM.DD bei shortDateTimeFormat versucht (gleiches Ergebnis)
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 17.04.07 15:32 
Interessant. Wenn das Ergebnis von StrToDate(Time) keiner Variable zugewiesen wird, kommt kein Fehler. Wie auch immer, diese Code funktioniert bei mir prima:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
Var Datums_Format: TFormatSettings;
    y: TDateTime;
Begin
    GetLocaleFormatSettings(0, Datums_Format);
    Datums_Format.DateSeparator := '.';
    Datums_Format.ShortDateFormat := 'yy.mm.dd';
    y := StrToDateTime('07.04.15', Datums_Format);
End;

(Genauso gehts auch mit DateTime)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Christoph Englmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Mi 18.04.07 08:59 
wiederum erstmal danke....


glaub mittlerweile, dass ich bescheuert bin...

hab jetzt folgenden Quellcode (der m.E. identisch ist zu Deinem):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TFormVTMap.Button1Click(Sender: TObject);
var
  Datums_Format :TFormatSettings;
  Datum_Tabelle :TDateTime;
begin
  inherited;
        GetLocaleFormatSettings(0,Datums_Format);
        Datums_Format.DateSeparator := '.';
        Datums_Format.ShortDateFormat :='yy.mm.dd';
        Datum_Tabelle := StrToDateTime('07.04.15',Datums_Format);



krieg immer noch die Meldung '07.04.15 ist keine gültige Datum/Zeit Angabe'... :-(((


christoph
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 20.04.07 22:05 
Spiel mal ein bisschen mit dem Code herum, ersetze den Array mit einer einzelnen Variable, lass das inherited weg, einfach nur um zu isolieren, woran es liegen könnte... :| Wär denkbar, dass du einen Bug von Delphi erwischt hast, hab schon von Leuten gehört, deren Probleme sich lösten, nachdem sie alles was sie hatten per STRG+C in ein neues Projekt kopierten ... Aber jetzt spiel erstmal etwas damit rum bzw. häng mal das Projekt an, damit wir versuchen können, den Fehler zu reproduzieren...

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.