IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
   ► KBTo/From GuidesReferenceData Structures  Print This     

Pointers (Cross Ref > Data Structures)

Pointers

General Info: Pointers / References

A pointer is a variable type that allows you to refer indirectly to another object. Instead of holding data, a pointer holds the address to data -- the address of another variable or object. You can change the address value a pointer points to thus changing the variable or object the pointer is pointing to.

A reference is a type of pointer that cannot change and it must always point to a valid storage (no nulls).

Access VBA:   Not Supported

Same as VB Classic. Access VBA does not offer developer defined pointers.

ASP Classic:   Not Supported

ASP Classic does not offer developer defined pointers.

C#: 

Although pointer data types in C# coding are less important than in other languages such as C++, C# does support developer defined pointers. Use the * operator to declare a pointer data type. Use the & operator to return the current address of a variable.

In .Net managed coding the use of pointers is not safe because the garbage collector may move memory around. To safely use pointers, use the unsafe keyword. However, avoid unsafe code if possible.

C++/CLI has more extensive support for pointers than C#. If you have needs that go beyond what C# offers, you can code in C++/CLI and add it to your project.

Syntax Example:
//Declare a pointer of type integer.
Integer *PCounter;

More Info

Definition:  Pointers / References

C++: 

C++ uses both pointers and references. Use the * operator to declare a pointer and use the & operator to declare a reference.

More Info / Comment

More Info

Definition:  Pointers / References

Corel Paradox: 

ObjectPAL doesn't have a developer defined pointer type except for use with DLLs where you use a special CPTR uses keyword to refer to a DLL string pointer data type.

Syntax Example:
Uses Tapi32
  tapiRequestMakeCall(sNumber CPTR, sAppName CPTR, 
    sLogName CPTR, sComment CPTR) CLONG
endUses


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Advanced

1 Advanced Level Question

Question #1: True or False?

ObjectPAL doesn't have a developer defined pointer type except for use with DLLs where you use a special CPTR uses keyword to refer to a DLL string pointer data type.

Answer:
  • True
  • False
  • More Info

    Definition:  Pointers / References
     

    Delphi: 

    Although pointer data types in Delphi coding are less important and not required for most general coding, Delphi fully supports developer defined pointers. Use a carrot (^) to declare a pointer data type. Use the @ operator or Addr function to return the current address of a variable.

    Delphi provides typed pointer types such as PChar and PExtended as well as a generic point to anything Pointer type.

    Nil is a special pointer value that you can assign to any type of pointer. Nil never points to any valid memory and indicates an unassigned or empty pointer.

    Syntax Example:
    //Declare a pointer of type integer.
    PCounter : ^Integer;
      
    //Assign a value to the location of a pointer.
    //Also known as dereferencing.
    PCounter^ := 8;
      
    //Assign address of A to B.
    PointerB := @PointerA;  //or...PointerB := Addr(PointerA);

    More Info

    Definition:  Pointers / References

    Delphi Prism: 

    Although pointer data types in Prism coding are less important than in other languages such as C++, Prism does support developer defined pointers. Use the ^ operator to declare a pointer data type. Use the @ operator to return the current address of a variable.

    In .Net managed coding the use of pointers is not safe because the garbage collector may move memory around. To safely use pointers, use the unsafe keyword. However, avoid unsafe code if possible.

    More Info / Comment

    More Info

    Definition:  Pointers / References

    Java:   Not Supported

    Java does not offer developer defined pointers.

    JavaScript:   Not Supported

    JavaScript does not offer developer defined pointers. However, you can use the eval function to simulate pointers.

    Perl: 

    Perl supports both pointers and references.

    PHP:   Not Supported

    PHP supports references which allow you to refer to the value of a variable but PHP does not support true developer defined pointers. You cannot get and use the address of a variable.

    However, you can still do inexpensive assignments by assigning by reference.

    VB Classic:   Not Supported

    VB6 does not officially offer developer defined pointers. However, VB5 and VB6 does have unsupported and undocumented VarPtr, StrPtr, and ObjPtr types but you probably should avoid them.

    VB.Net:   None

    VB.Net doesn't support pointers. The closest it comes is IntPtr which you use to get pointer handles on windows, files, etc.

    C# does have better support for pointers and C++/CLI has extensive support. One solution when it's really needed in VB.Net is to code in C# or C++/CLI and add it to your project.

    However, VB.Net does support references.

    More Info / Comment

    Linked Certification Question(s)

    The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

    Advanced

    1 Advanced Level Question

    Question #1: Multiple Choice

    Which statement best describes pointer support in VB.Net?

    Answer:
    1. 

    VB.Net supports developer defined pointers. Use the * operator to declare a pointer data type. Use the & operator to return the current address of a variable.

    2. 

    VB.Net supports developer defined pointers. Use a carrot (^) to declare a pointer data type. Use the @ operator or Addr function to return the current address of a variable.

    3. 

    VB.Net doesn't support pointers. The closest it comes is IntPtr which you use to get pointer handles on windows, files, etc.

    More Info

    Definition:  Pointers / References
     




    Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
    www.prestwood.com


    ©1995-2024 Prestwood IT Solutions.   [Security & Privacy]