Access Violation in Code

Asked

Viewed 78 times

1

Gentlemen, I have this code, it lies in my Form Activate, then, it serves to identify my running software, and consequently update it, ie 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 anyone tell me why?

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). The way you are iterating from 0 to 5 (6 iterations), so will occur access Violation.

  • Still keeps making the mistake.... : S

  • Does access Violation occur at the first execution of the line of code? Does this array actually have the required number of positions? This error most likely indicates that you are trying to access within "vparam" a non-existent position...

  • Provavemnte @Arthurdeandrade, has a function that determines the size of the array, I’m checking now.

  • No longer giving access to Violation friend, thank you.

  • Before you leave, there’s a way to explain what this one’s for ParamCount? Thank you

  • 1

    Paramcount simply contains the number of parameters that have been used to invoke the executable in opening it. So if you pass as parameters in the opening, for example, the server name, the user, and the permission level, the Paramcount value will be 3.

  • I got it, thank you very much, buddy.

Show 2 more comments

Browser other questions tagged

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