Hey,
So I am getting Delphi classes at school, piece of cake ofcourse and I enjoy it a lot.
But I have an error which doesn't give me enough info to fix it.
Can you help me?
Code:
//I have this in the global scope
const
AllowedChars : array[0..10] of char = ('1','2','3','4','5','6','7','8','9','.','0') ;
//the procedure
function Allow(str:string):string;
var
//AllowedChars: array of char;
AllowedLength, i, i2 :integer;
Switch : Boolean;
begin
AllowedLength := 11;
for i := 1 to Length(str) do
begin
for i2 := 0 to (AllowedLength - 1) do
begin
### if (str[i] = AllowedChars[i2]) then Switch := true;//acces violation error.
if (not((i2 =AllowedLength - 1) and (Switch = true))) then Delete(str, i, 1);
end;
switch:=false;
end;
end;
//The event(on edit text change)
//when I type a char as 9 it crashes immidiately
procedure TForm1.txtLengthChange(Sender: TObject);
var
Str:string;
begin
Str := txtlength.text;
txtlength.text := Allow(Str);
end;
I commented the line which gives me the error.
I marked it with ###(the line which gives me the error)
My goal is to chech the input and I want it to be one of my AllowedChars(array of char) so I loop the input string and but before any logical error can be created it already crashes on the first loop. It isn't a synatax error neither logical so something between.
In short: how can I fix the acces violation error on the ### marked line.
I haven't been visiting forums, especially english forums, anymore so my English sucks a lot. I will put this through a spell checker when I get home.
Greetings,
Hermen