unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
AgOpenDialog, StdCtrls;
type
TStringDynArray =
array of string;
type
TForm1 =
class(TForm)
Button1: TButton;
AgSaveDialog1: TAgSaveDialog;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
function GetExtension(Filter:
string;
const Index: Integer):
string;
function Explode(
const Separator, S:
string; Limit: Integer = 0): TStringDynArray;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.Explode(
const Separator, S:
string; Limit: Integer = 0): TStringDynArray;
var
SepLen: Integer;
F, P: PChar;
ALen,
Index: Integer;
begin
SetLength(Result, 0);
if (S = '
')
or (Limit < 0)
then Exit;
if Separator = '
'
then
begin
SetLength(Result, 1);
Result[0] := S;
Exit;
end;
SepLen := Length(Separator);
ALen := Limit;
SetLength(Result, ALen);
Index := 0;
P := PChar(S);
while P^ <> #0
do
begin
F := P;
P := AnsiStrPos(P, PChar(Separator));
if (P =
nil)
or ((Limit > 0)
and (
Index = Limit - 1))
then P := StrEnd(F);
if Index >= ALen
then
begin
Inc(ALen, 5);
SetLength(Result, ALen);
end;
SetString(Result[
Index], F, P - F);
Inc(
Index);
if P^ <> #0
then Inc(P, SepLen);
end;
if Index < ALen
then SetLength(Result,
Index);
end;
function TForm1.GetExtension(Filter:
string;
const Index: Integer):
string;
var
List: TStrings;
i:integer;
Teile: TStringDynArray;
begin
Result := '
';
List := TStringList.Create;
try
Teile:=Explode('
|', Filter);
for i:=0
to Length(Teile)-1
do
List.Add(Teile[i]);
Result := ExtractFileExt(List[Pred(
Index*2)]);
finally
FreeAndNil(List);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AGSaveDialog1.Filter:='
Text-Dateien (*.txt)|*.TXT|Excel-Dateien (*.xls)|*.XLS|dBase-Dateien (*.dbf)|*.DBF|Bitmap-Dateien (*.bmp)|*.BMP|Meta-Dateien (*.wmf)|*.WMF';
if AgSaveDialog1.Execute
then
ShowMessage(ChangeFileExt(AgSaveDialog1.FileName,
GetExtension(AgSaveDialog1.Filter, AgSaveDialog1.FilterIndex)));
end;
end.