Recent

Author Topic: error whith option Verify method calls  (Read 2307 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 618
error whith option Verify method calls
« on: July 28, 2015, 10:23:04 pm »
When the option "Verify method calls" is checked  in de debugging options then i get an error on the next code:
Code: [Select]

var
arBestanden : array[1..250] of string;
i : Integer;
begin
  if arteller > 0 then
    begin
      for i := arteller downto 0 do
        begin
          deletefile(arBestanden[i]);
          arteller := arteller -1;
        end;
    end; 
end;
 


the error is a range check error on the line:

Code: [Select]
deletefile(arBestanden[i]);

bylaardt

  • Sr. Member
  • ****
  • Posts: 309
Re: error whith option Verify method calls
« Reply #1 on: July 28, 2015, 10:52:56 pm »
arBestanden[0] ??
your array begins from 1 [1..250]

change your "downto 0" to "downto 1"  or fix your array [0..250]

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: error whith option Verify method calls
« Reply #2 on: July 29, 2015, 02:56:48 am »
If the array indexes are causing you headaches, you might want to consider using the constructs low and high.

for i := arteller downto low(arBestanden) do

or

For i := low(arBestanden) to High(arbestanden)

Because you use a separate index, something like thing might be helpful as well:

Code: [Select]
Type
  arBestandenRange = 1..250;
var
  arTeller: arBestandenRange;
  arBestanden : array[arBestandenRange] of string;
  i : arBestandenRange;
begin
  if arteller >= low(arBestanden) then
  begin
    for i := arteller downto low(arBestanden) do
      begin
        deletefile(arBestanden[i]);
        arteller := arteller -1;
      end;
  end; 
end;

Or what would be my favourite:
Code: [Select]
Type
  arBestandenRange = 1..250;
var
  arTeller: arBestandenRange;
  arBestanden : array[arBestandenRange] of string;
begin
  while arTeller > low(arBestanden) do
  begin
    dec(arteller);
    deletefile(arBestanden[arTeller]);
  end;
end;

The range takes the headaches away because when you "out of range" the compiler will tell so, as well as runtime (when enabled).
« Last Edit: July 29, 2015, 03:14:07 am by molly »

Hansvb

  • Hero Member
  • *****
  • Posts: 618
Re: error whith option Verify method calls
« Reply #3 on: August 04, 2015, 10:44:57 pm »
My array starts with 1 and use downto 0. Stupid mistake.

 

TinyPortal © 2005-2018