Autor Beitrag
rob87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 16.04.08 10:26 
Hallo,

irgendwie versteh ichs grad ned.

Ich hab eine String[2]-Variable, in der drinsteht '01' -> '12'
Und nun will ich in einem messagedlg meine Variable so umformatieren, dass er Februar ausgibt.

Das Wesentliche ist ja nur der Unterschied zwischen dem Format 'mm' und 'mmmm'


Ich steh grad aufm Schlauch. Bitte helfts mir.

Merci, Robert
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mi 16.04.08 11:15 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var   s : String;
      d : TDateTime;
begin
  s := '11';
  d := StrToDateTime ('1.' + s + '.2008');
  s := FormatDateTime ('mmmm', d);
  ShowMessage (s);
end;


Das ganze funktioniert in Abhängigkeit von den lokalen Einstellungen im System, soll heissen dieses Beispiel funktioniert mit deutschen Standardeinstellungen.
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 16.04.08 11:40 
Eindeutschen kannst Du es bei Bedarf selbst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function extmonthname(themonth:integer):string;
begin
  result := 'January';
  if themonth=2  then result := 'February';
  if themonth=3  then result := 'March';
  if themonth=4  then result := 'April';
  if themonth=5  then result := 'May';
  if themonth=6  then result := 'June';
  if themonth=7  then result := 'July';
  if themonth=8  then result := 'August';
  if themonth=9  then result := 'September';
  if themonth=10 then result := 'October';
  if themonth=11 then result := 'November';
  if themonth=12 then result := 'December';
  extmonthname := result;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption := extmonthname(StrToInt('02')); //Beispiel = Feb
end;
oldmax
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 380


D3 Prof, D4 Prof
BeitragVerfasst: Mi 16.04.08 11:54 
Hi
Warum nicht mit Case?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
Function MonToStr(Mon: String):String;
Var M : Integer;
Begin
  M:=StrToInt(Mon); // oder man übergibt direkt einen Integer
  Case M of 1: Result:='Januar';
            2: Result:='Februar';
etc. 
  end;
End;
oder ein Array[1..12] of String[10] initialisiert mit den Monatsnamen und dann direktem Zugriff.
da gibt's doch so vielle Möglichkeiten....
Gruß oldmax

_________________
Zier dich nich so, ich krieg dich schon....
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 16.04.08 11:54 
Aber bitte nicht so. :eye:
Ich würde dir ein Array vorschlagen:
ausblenden Delphi-Quelltext
1:
2:
3:
const
 MonthList: Array[1..12] of String = (
 'Januar','Februar',...,'Dezember');
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 16.04.08 12:16 
Hallo,

Delphi liefert doch schon alles, und passend zu den Systemeinstellungen.:
ausblenden Delphi-Quelltext
1:
Showmessage(LongMonthNames[StrToInt('01')]);					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 16.04.08 12:23 
user profile iconLannes hat folgendes geschrieben:
Hallo,

Delphi liefert doch schon alles, und passend zu den Systemeinstellungen.:
ausblenden Delphi-Quelltext
1:
Showmessage(LongMonthNames[StrToInt('01')]);					


Wunderbar. Das ist ideal. Von wegen Array, oder so. Brauch ich alles ned. Super!! Merci.
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 16.04.08 12:46 
LongMonthNames ist aber ungeeignet, wenn man ein Programm in einer bestimmten Sprache darstellen will z.B. Englisch, es aber auf einem WINDOWS mit deutschen Landeseinstellungen läuft - da gibt es Sprachen-Mischmasch! UNSCHÖN!!!
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 16.04.08 13:26 
user profile iconrob87 hat folgendes geschrieben:
user profile iconLannes hat folgendes geschrieben:
Hallo,

Delphi liefert doch schon alles, und passend zu den Systemeinstellungen.:
ausblenden Delphi-Quelltext
1:
Showmessage(LongMonthNames[StrToInt('01')]);					


Wunderbar. Das ist ideal. Von wegen Array, oder so. Brauch ich alles ned. Super!! Merci.

Ein Blick in die DOH verrät uns folgendes:
DOH hat folgendes geschrieben:
LongMonthNames is the array of strings containing long month names.

ausblenden Delphi-Quelltext
1:
var LongMonthNames: array[1..12] of string;					

Bis auf die Tatsache, dass meine Lösung sich auf eine Sprache spezifiziert, sind die doch gleich. :)
Soviel zum Thema Array. ;)

Cheers,
Marc