Re: passing data to functions in other units

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 08/31/04


Date: Tue, 31 Aug 2004 12:22:50 -0400


"Kris Leech" <krisleech@email.com> wrote in message
news:ch2818$p4h$1@titan.btinternet.com...

> I assume i can either pass the whole variable to the functions (which
> may be slow?) or pass a pointer to the global variable??

No slower than the time it takes you to sort out any bugs that may occur
because of a poorly choosen passing mechanism ;).

> The global variable i have is a static array of bytes.

Check out the "Parameter Semantics" section of the ObjectPascal (Delphi)
Language Reference portion of the help. (If you can't find it, look up
'value parameters' in the help.)

There are three passing mechanisms in Delphi that you should consider. By
value, the default, will copy the passed variable or expression. When
dealing with arrays this can have an impact on performance. But it does let
the routine freely alter the passed values without worrying about any impact
on the rest of the program. By reference, Var, effectively passes the
address of the passed variable. The routine is therefore working with the
passed variable, not a copy. A third mechanism, Const, allows the compiler
to pick the most efficient passing mechanism. The only proviso is that the
routine cannot attempt to alter the parameter.

So, if you are doing something like adding all the values in a vector, Const
would be the most appropriate choice. But if you were inverting a matrix, in
place, Var would be a better choice. And finally, if you had to sort the
array to find the middle value and didn't want to sort the passed array,
by-value would be the most appropriate choice.



Relevant Pages

  • Re: How to perform an automated AutoFilter sort
    ... use this code but, instead of processing the row, add the ID to an array. ... you want to process them in alphabetical order, then you also need a sort ... Then send that array to the routine that does the ... >> Dim Product As String ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Deleting blank values from an array
    ... I would like to sort the array with the earliest date in Hand the blank ones deleted by redimensioning the array. ... Is there an easy way to delete the empty elements of the array either while sorting or another routine after the sort? ... I used the sorting routines in this help site ...
    (microsoft.public.excel.programming)
  • Re: Filesearch returning files not in alphabetical order?
    ... is a routine that I think does get the path names in alphabetical order. ... There are plenty of routines around to sort a 1-D or 2-D array. ... > on that - I just don't know how to alphabetize an array. ...
    (microsoft.public.excel.programming)
  • RE: Deleting blank values from an array
    ... Thanks Greg. ... Your routine will work. ... eliminate the blank entries before they are added to the array. ... > sort afterwards. ...
    (microsoft.public.excel.programming)
  • Re: "Sorting" assignment
    ... And many others prefer to call partition exchange because "quicksort" ... bin B depending on whether it is greater than, ... If the array is already sorted, this means that you end up ... attempt to sort them. ...
    (comp.programming)