function Match(const Source, Target: string): Boolean;
function DoMatchSubtine(Index: Integer; const SubStr: string): Boolean;
var
I, N: Integer;
begin
Result := False;
N := Length(SubStr);
if Index > Length(Source) then
Result := N = 0
else if Length(Source) > 0 then
begin
if Source[Index] = '*' then
begin
if N = 0 then
Result := DoMatchSubtine(Index + 1, '')
else
for I := 1 to N + 1 do
begin
Result := DoMatchSubtine(Index + 1, Copy(SubStr, I, N + I - 1));
if Result then
Break;
end;
end
else if Source[Index] = '?' then
begin
if N > 0 then
Result := DoMatchSubtine(Index + 1, Copy(SubStr, 2, N - 1))
end
else
begin
if N > 0 then
if Source[Index] = SubStr[1] then
Result := DoMatchSubtine(Index + 1, Copy(SubStr, 2, N - 1));
end;
end;
end;
begin
Result := DoMatchSubtine(1, Target);
end;