ShowMessage displays the message 2 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 , I click ok and it repeats the same message.

    
asked by anonymous 14.12.2015 / 12:51

1 answer

3

The problem is in your for, is passing 2 times, thus showing 2 messages; Do as follows:

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 have helped.

    
14.12.2015 / 13:19