If in your Edit1.Text you have the string:
'0..9'
Then the following code should help you:
var
AValidChars: SysUtils.TSysCharSet;
StartChar, EndChar: char;
c: char;
begin
StartChar := Edit1.Text[1]; // some validation should be done
EndChar := Edit1.Text[4];
AValidChars := [];
for c := StartChar to EndChar do
Include(AValidChars, c);
end;
A Delphi/Pascal parser can be used to validate the input.
Update:
More elaborated function supporting set constructors:
function StrToSysCharSet(const S: string): TSysCharSet;
var
Elements: TStringList;
CurrentElement: string;
StartChar, EndChar: char;
c: char;
i: Integer;
p: Integer;
function ReadChar: Char;
begin
Result := CurrentElement[p];
Inc(p);
end;
function NextIsDotDot: Boolean;
begin
Result := '..' = Copy(CurrentElement, p, 2);
end;
begin
Elements := TStringList.Create;
try
Elements.CommaText := S;
Result := [];
for i := 0 to Elements.Count - 1 do
begin
CurrentElement := Trim(Elements[i]);
p := 1;
StartChar := ReadChar;
if NextIsDotDot then
begin
Inc(p, 2);
EndChar := ReadChar;
for c := StartChar to EndChar do
Include(Result, c);
end
else
Include(Result, StartChar);
end;
finally
Elements.Free;
end;
end;
It can be used like this:
S := '0..9, a..z';
AValidChars := StrToSysCharSet(S);
or
S := '0..9 and a..z';
AValidChars := StrToSysCharSet(AnsiReplaceText(S, ' and ', ', '));
Adapting to support
S := '''0''..''9'' and ''a''..''z'''
is simple.