xHarbour Reference Documentation > Statement Reference xHarbour Developers Network  

MEMVAR

Declares PRIVATE or PUBLIC variables.

Syntax

MEMVAR <varName,...>

Arguments

MEMVAR <varName,...>
This is a comma separated list of symbolic names identifying field variables.

Description

The MEMVAR statement declares symbolic names of dynamic memory variables of PRIVATE or PUBLIC scope. This instructs the compiler to resolve unaliased variable names to memory variables, not field. All variables listed in <varName,...> that appear in program code without alias name and alias operator, are treated as if they are listed with the M-> alias name.

The scope of the MEMVAR statement depends on the place of declaration:

1. When the MEMVAR declaration appears at the top of a PRG file before any other executable statement, the declaration has file wide scope, i.e. it is valid throughout the entire PRG file.

2. When the MEMVAR declaration follows a FUNCTION, METHOD or PROCEDURE declaration, the variable is treated as memory variable only in the routine that declares the MEMVAR.

The lines in PRG source code preceding the MEMVAR declaration may not call executable code. They can only contain declaration statements, i.e. only the FUNCTION, METHOD, PROCEDURE statements, and the FIELD, LOCAL, PARAMETERS, or STATIC variable declarations are allowed to precede the MEMVAR statement.

Info

See also:FIELD, GLOBAL, LOCAL, PRIVATE, PUBLIC, STATIC
Category: Declaration , Statements

Example

// The example demonstrates the difference of a declared and
// undeclared memory variable of PRIVATE scope.

   MEMVAR myVar

   PROCEDURE Main
      x := "myVar"              // compiler warning
      myVar := "Hello World"    // no compiler warning

      ? x
      ? &x
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe