Home > Enterprise >  I have a Delphi assignment. If I input text into my edit box and it’s less than 6 letters than it mu
I have a Delphi assignment. If I input text into my edit box and it’s less than 6 letters than it mu

Time:09-17

I'm pretty sure my problem is due to an If statement.

I have to make a procedure where if I insert a certain amount of characters into the edit box and that amount is less than 5 then it will tell me “showmessage’please ensure that the password is more than 5 characters’; but if it’s more than five letters than it would print it on the Memo form. But I want to make it all in 1 button. Any ideas?

var, var
sName : string ;

sName := edit1.text ;
if edit1.text > 6 then
begin
  showmessage’please ensure that etc.’
end;

this doesn’t seem to be working and I think it’s because the string and integer doesn’t work together.

CodePudding user response:

Yes, your assumption is correct - you are trying to compare a string with a number, which is a no-go in Delphi.

You need to check the length of the inputted text, so the IF statement should be:

if length(edit1.text) > 6 then 

Also, note that you say "more than 5" but your code says "larger than 6".

CodePudding user response:

TEdit has a GetTextLen() method which returns the number of characters entered:

if Edit1.GetTextLen < 5 then
begin
  ShowMessage('please ensure that etc.');
end else
begin
  // use Edit1.Text as needed...
end;
  • Related