Hallo Robin,
Solch eine IF-Verschachtelung ist nicht wirklich sinnvoll und übersichtlich.
Wenn es wirklich mal nicht anders geht, dann mach doch zum Beispiel folgendes...
Delphi-Quellcode:
if A = B then
Result:=''
else if A = C then
Result:=''
else if A = D then
Result:=''
:
:
hier wird nur solange noch weiter verglichen, bis ein Treffer gefunden wurde.
Danke
marabu für den Registry-Hinweis, so ist es natürlich am sinnvollsten.
Wenn man aber mal solch eine Struktur wie sie Robin vorgeschlagen hat braucht, dann kann man das etwas eleganter über ein konstantest Array lösen.
Delphi-Quellcode:
type
TTyp = (tNone, tPictures, tTexte, tSource, tOtherFiles);
TMyResult =
record
Endung:
string;
Beschreibung:
string;
Typ:TTyp;
end;
:
:
function GetFullExt(
const FileName:
string): TMyResult;
type
TBeschreibung =
record
A:
string[7];
B:TTyp;
C:
string;
end;
const
INFOS:
array[1..25]
of TBeschreibung = (
(A: '
jpg'; B:tPictures; C:'
JPG / JPEG Bild'),
(A: '
jpeg'; B:tPictures; C:'
JPG / JPEG Bild'),
(A: '
ico'; B:tPictures; C:'
Windows Symbol'),
(A: '
bmp'; B:tPictures; C:'
Windows Bitmap'),
(A: '
gif'; B:tPictures; C:'
GIF Bild'),
(A: '
tif'; B:tPictures; C:'
Windows Foto Format'),
(A: '
xcf'; B:tPictures; C:'
GIMP Bild'),
(A: '
doc'; B:tTexte; C:'
Microsoft Word Dokument'),
(A: '
xls'; B:tTexte; C:'
Microsoft Exel Tabelle'),
(A: '
txt'; B:tTexte; C:'
Textdokument'),
(A: '
rtf'; B:tTexte; C:'
Rich Text Format'),
(A: '
pas'; B:tSource; C:'
Delphi Quellcode'),
(A: '
dfm'; B:tSource; C:'
Delphi Formular Datei'),
(A: '
dpr'; B:tSource; C:'
Delphi Projekt'),
(A: '
bdsproj'; B:tSource; C:'
Borland Developer Studio Project File'),
(A: '
dcu'; B:tSource; C:'
Delphi Compilierte Unit'),
(A: '
res'; B:tSource; C:'
Ressource Datei'),
(A: '
cs'; B:tSource; C:'
C# Source File'),
(A: '
bat'; B:tSource; C:'
Stapelverarbeitungsdatei für MS-DOS'),
(A: '
exe'; B:tOtherFiles; C:'
Ausführbare Datei'),
(A: '
dll'; B:tOtherFiles; C:'
Dynamic Link Library / Programmbibliotek'),
(A: '
eml'; B:tOtherFiles; C:'
Internet E-Mail Nachricht'),
(A: '
hlp'; B:tOtherFiles; C:'
Hilfedatei'),
(A: '
ini'; B:tOtherFiles; C:'
Konfigurations einstellung'),
(A: '
log'; B:tOtherFiles; C:'
"Logbuch"-Datei')
);
var
Ext:
string;
i:integer;
abbruch:boolean;
begin
Ext:=lowercase(ExtractFileExt(FileName));
i:=low(INFOS);
abbruch:=false;
while (i <= high(INFOS))
and not abbruch
do begin
abbruch:=(Ext = INFOS[i].A);
if not abbruch
then
inc(i);
end;
if abbruch
then begin
Result.Endung:=INFOS[i].A;
Result.Typ:=INFOS[i].B;
Result.Beschreibung:=INFOS[i].C;
end
else begin
Result.Endung:='
';
Result.Typ:=tNone;
Result.Beschreibung:='
unbekannte Dateierweiterung';
end;
end;
So ist eine Erweiterung noch sehr einfach möglich. Robin bei deinem Beispiel hast du gleich nach dem ersten Typ aufgegeben auch noch gross/klein zu unterscheiden. Bei meinem Vorschlag braucht man nur noch an einer Stelle einmal etwas definieren, dass dann für alle Inhalte im Array gilt.
Naja, ist nur ein Vorschlag.
MfG
Thorsten