Hi there. Sorry, that was a very vague code explanation attempt from me. I am learning about data handling and number conversion in Object Pascal. So, the program I am attempting to make is to take a user’s input of a fixed length. Store the value and then allow them to point to a digit and change just the selected value.
For example user enters 25697 -> value gets stored in an Array (or something more suitable) -> display the array, i.e.:
index1 [2]
index2 [5]
index3 [6]
index4 [9]
index5 [7]
-> Allow the user to select what number to replace by selecting the index number. -> Then generate a new number showing the changes.
In my earlier code attempt I was trying to say that if the user inputs a 0 as the first number then display and error message. I hope this helps.
For some reason I didn't see this post before. I suppose the odd thing to me is the need for another array for storage, but your post suggests that you are not so attached to that. You can simply store the user input into a variable as a string, then display that string in say a separate edit box. Especially since you are not doing any calculations or math on user input.
You could do simple checks to make sure that 0 is never the first number, no more than 5 digits are given, and that they are all numbers.
The user can simply retype the 5 digit number, if they want to resubmit. Because the user might want to change multiple numbers, so instead of going crazy with that, just let them retype the entire 5 digit number. Just have say a second edit box where they can see the original number they typed.
Maybe something like the below:
procedure TForm1.Button1Click(Sender: TObject);
var
Input: String;
SeeScan: PChar;
Count: SmallInt;
Flag: Boolean;
const
Numbers = '0123456789';
begin
Input := Edit1.Text;
Edit1.Clear;
Flag := True;
for Count := Low(Input) to High(Input) do
begin
SeeScan := StrScan(Numbers, Input[Count]);
if ((Count = 1) AND (Input[Count] = '0')) OR (SeeScan ='') OR (Count > 5) then
begin
ShowMessage('Restrictions:' + #10 + '0 not allowed as 1st number' + #10 + 'Must be less than 5 digits' + #10 + 'Only numbers');
Flag := False;
break;
end;
end;
if (Flag = True) then
begin
ShowMessage('Is a number and less than 5 digits');
Edit2.Text := Input;
end;
end;