Access Violation in Code

1

Gentlemen, I have this code, it is located in my Form Activate , so it serves to identify my software that is running, and consequently update it, that is, it is an auto updater.

if servidor = false then   //se o servidor estiver conectado
        begin
          for i := 0 to ParamCount  do      //contador para verificar os parametros
            begin
              if vparam[i] <> ExtractFileName(Application.ExeName) then <---Acess Violation aqui!
                begin
                ........
                end;
            end;
         end;  

In the comment indicates the line of Acess Violation, could someone tell me why?

    
asked by anonymous 19.07.2014 / 13:13

1 answer

3

You need to use for i := 0 to (ParamCount -1) do since if the number of parameters is 5, you will have to iterate from 0 to 4 (ie, 5 iterations). As it is you are iterating from 0 to 5 (6 iterations), so access violation will occur.

    
19.07.2014 / 14:02