Results 1 to 9 of 9

Thread: Range Check Error...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Range Check Error...

    Hi I've got this stupid range check error. I can not define the size of arrays in the input section when declaring and defining functions. altough if I do not define them it will be empty and will create range check error. The solution is just way too simple for me to find it as usually can someone help me?

    ******************************
    Details: my function is something like this:
    Function myfunction(input1:array of integer; input2:array of integer):real;
    {defining as function myfunction(input1:array[1..9] of integer;input2:array[1..9] of integer):real;
    will result in error "of expected [ found"}
    begin
    {calculations...}
    myfunction:=calculated_value;
    end;
    I declare array and an output variable in the main program:
    var
    array1,array2:array[1..9] of integer;
    variable:real;
    I then want to call my function

    variable:=myfunction(array1,array2);
    and then it says Error 201(Which is range check error)

    Thanks in forward

  2. #2
    You cannot do this:

    Code:
    function myfunction(somecrazyinputthingy: array [0..154] of Integer): Integer;
    You can only use simple pre-defined types for your arguments. To solve this, just define the type you want:

    Code:
    TMyCrazyArrayType = array [0..154] of Integer;
    
    function myfunction(somecrazyinputthingy: TMyCrazyArrayType): Integer;
    Have a nice day.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3
    But you have to remember that
    Code:
    Function myfunction(input1, input2: array of integer):real;
    and
    Code:
    type TMyIntArray = array[1..9] of integer;
    pMyIntArray = ^TMyIntArray;
    Function myfunction(input1, input2: pMyIntArray):real;
    are propably faster than
    Code:
    TMyCrazyArrayType = array [0..154] of Integer;
    function myfunction(somecrazyinputthingy: TMyCrazyArrayType): Integer;
    because the 2 upper versions only send a pointer to the array, don't make actual copies of each of the element in it. Especially if the array is big, copying it all in would be extremely bad coding.

  4. #4
    Ah yes. Good point.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #5
    Thanks this way it works fine. I've never used pointers because I do not exactly understand them. What is the difference between a pointer and the variable itself except for the pointer uses less memory?

  6. #6
    Yes, pointers are one of the harder things about programming. I'll have some links for you:

    http://delphi.about.com/od/objectpas...a/pointers.htm

    http://www.delphibasics.co.uk/Article.asp?Name=Pointers

    Ok, I'll breifly explain them:

    All your variables are stored in RAM memory. Pointers are also stored there, but they point to another location in RAM. They don't contain value's like 6 or "abc", but memory adresses.
    A quick example:

    Code:
    //Make a new pointer type that points to integers (not sure if this allready exists)
    type
      pinteger = ^integer; 
    
    var
      v, w: integer;
      p: pinteger;  
    begin
      v := 100;
      w := 50;
      p := @v;  //the value of p is now the memory location of v
    
      showmessage( IntToStr( p^ ) );  //Output: 100 (^ means: show us what is stored at this memory location)
    
      v := v + 10;
    
      showmessage( IntToStr( p^ ) );   //Output: 110 
    
      p := @w;  //Let p point to w now
    
      showmessage( IntToStr( p^ ) );  //output 40
    
      p := nil;  //NIL means "points to nothing"
    
      showmessage( IntToStr( p^ ) );  //gives an error
    end;
    Hope that helps.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •