Showmessage presents the message 2 times

Asked

Viewed 80 times

4

I have the following code below:

 for i := 1 to form1.variavel do
        with form1 do
       if TEdit(FindComponent('edt_variavel'+IntToStr(i))).Text = '' then
        begin
         showmessage ('Preencha os campos em branco')
        end
        else
 form2.showmodal;

it checks for blank fields and displays a message if it exists.

In the application it shows the message 2 times, it shows Preencha os campos em branco, click ok and it repeats the same message.

1 answer

3


The problem is in your for, is passing 2 times, thus showing 2 messages; Do it this way:

boolean existeCamposVazio := false;

for i := 1 to form1.variavel do begin

       if TEdit(FindComponent('edt_variavel'+IntToStr(i))).Text = '' then begin
         existeCamposVazio = true;
         break;
       end;
 end;      

 if (existeCamposVazio) then
     showmessage ('Preencha os campos em branco');
   end else begin 
      with form1 do
     form2.showmodal;
   end;

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.