On May 23, 2006, at 11:47 AM, Chris Jett wrote:

Let me see if I can break down this Byref issue I'm having as simply as possible.

I have an array called ScanQueue. This is an array of a custom class named "Message" which has a FolderItem property called MessageFile. I have a method (called VirusScan) that I want to pass the first element of the array to Byref so that it operates on that element of the array directly. The VirusScan method returns true if the Message object it was passed is not infected with a virus, but it also needs to change some properties of the Message object it is passed.

Here's my code where I get an error on compile:

      if VirusScan(ScanQueue(0)) then
        ScanQueue(0).MessageFile.MoveFileTo IncomingMailFolder
        ScanQueue.Remove(0)
      else

Here's the error message I get on compile: "You can't pass an expression as a parameter that is defined as ByRef."

Um... OK.  Why not?
--

Because the compiler says you can't. Basically, you can only pass dot-free expressions by reference. Why this is so has been beaten to death before. As I recall, the reason is to ensure that the object passed exists during the life of the subroutine. While it might be possible to change this, it would be complicated to implement (and probably to maintain) and you'd have lots of special cases to remember. The current system works and the rules are easy to remember.

In your case, you don't need to pass the VirusScan parameter by reference; you can always change properties of a parameter; passing by reference is needed only to change the parameter itself. You might take a look at <http://www.declaresub.com/Articles/ ObjectReferences.html>.

Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to