Delphi's type and a pointer

2011-01-03  来源:本站原创  分类:CPP  人气:128 

First statement: Do not I say these things as a textbook, this is my humble opinion; also want correction.

Delphi pointer into "pointer type" and "non-pointer type" categories.
Delphi, the type commonly used there must be hundreds, we can define the appropriate type for each type of pointer.
In fact, Delphi has been for many types of predefined indicators, such as data types:
Integer has a corresponding PInteger;
Char has a corresponding PChar;
string has a corresponding PString;
Another example:
TPoint has a corresponding PPoint;
TColor have corresponding PColor and so on.

In addition, the pointer can also be a pointer, such as: PChar is a character pointer, PPChar is PChar pointer (which are predefined Delphi).

According to the above example, we first summarize the types and pointers naming rules:
Type of contract with T Heading (Delphi except for regular data types, such as: String);
Agreement with the P pointer beginning with;
Agreement with the PP pointer to begin with.
Sub-types and the pointer is not the two concepts, the pointer itself is a type - "pointer type."

First get to know the pointer to the relevant operator (@,^, Addr):

@ @ Variable Get a pointer variable
Addr Addr (variable)
^ Pointer ^ Get pointer to the actual data
var Pxxx: ^ type Defined Pxxx some type of pointer variables
type Pxxx = ^ type Defined as some type of pointer Pxxx

For example:

unit Unit1;


  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);

  Form1: TForm1;


{$R *.dfm}

//Integer  And  PInteger
procedure TForm1.Button1Click(Sender: TObject);
  int: Integer;
  pint: PInteger; { Defines the type of the pointer, pointer to Integer type }
  int := 100;
  pint := @int;        { Pint is now  int  Pointer }
  pint^ := pint^ + 1;  { Now  pint^  And it is one thing to int ,  Test :}
  ShowMessage(IntToStr(int));   {101}
  ShowMessage(IntToStr(pint^)); {101}

// Define type pointer directly
procedure TForm1.Button2Click(Sender: TObject);
  int: Integer;
  PMyInt: ^Integer;
  int := 100;
  PMyInt := Addr(int); { This sentence and : PMyInt := @int;  The same }
  PMyInt^ := PMyInt^ + 1;
  ShowMessage(IntToStr(int));     {101}
  ShowMessage(IntToStr(PMyInt^)); {101}

// To customize a pointer type
procedure TForm1.Button3Click(Sender: TObject);
  PInt = ^Integer;
  int: Integer;
  PMyInt: PInt;
  int := 100;
  PMyInt := @int;
  PMyInt^ := PMyInt^ + 1;
  ShowMessage(IntToStr(int));     {101}
  ShowMessage(IntToStr(PMyInt^)); {101}

// A pointer to the pointer
procedure TForm1.Button4Click(Sender: TObject);
  int: Integer;
  pint: PInteger;
  ppint: ^PInteger;
  int := 100;
  pint := @int;
  ppint := @pint;
  ppint^^ := ppint^^ + 1;
  ShowMessage(IntToStr(int));     {101}
  ShowMessage(IntToStr(pint^));   {101}
  ShowMessage(IntToStr(ppint^^)); {101}


Know that these can operate, and can read other people's code; However, to fully understand how the matter in the end pointer, you need to talk from memory.


<script type="text/javascript"> </ script>

  • Delphi's type and a pointer 2011-01-03

    First statement: Do not I say these things as a textbook, this is my humble opinion; also want correction. Delphi pointer into "pointer type" and "non-pointer type" categories. Delphi, the type commonly used there must be hundreds, we

  • Delphi BDE ('Type mismatch for field "xxxx", expecting: Integer actual: Float') 2010-05-21

    Encountered this problem, the database of a field, such as l_id type is number (10) IDE: delphi5; Database connection: BDE Database: oracle 10.2.0 Problem when adding fields, l_id is number (10) fair to say add fields should correspond to the TIntege

  • dll written in java and Delphi interaction 2010-09-05

    Sometimes, when the project will inevitably develop and hardware development kits provided access to, the development of the interface is not written in Delphi c written. Following the development of a Delphi dll, which carried out a variety of inter

  • 『Delphi and C + + data types table』 2010-12-16

    『Delphi and C + + data types table』 Word Delphi / C + + range ShortInt 8-bit signed integer signed char SmallInt 16-bit signed integer short LongInt 32-bit signed integer int Byte 8-bit unsigned integer unsigned char Word 16 bit unsigned integer unsi

  • DELPHI based development skills 2011-05-03

    DELPHI basic development skills ◇ [DELPHI] My Network Places to copy files uses shellapi; copyfile (pchar ('newfile.txt'), pchar ('/ / computername / direction / targer.txt'), false); ◇ [DELPHI] the mouse drag effect produced by MouseMove event, Drag

  • bool type 2010-03-29

    #import <Foundation/Foundation.h> /* *c Language has a Boolean data type that has true and false values, the objective -c Provides the types BOOL, met with YES and NO values */ BOOL areIntsDifferent(int thing1,int thing2){ if(thing1==thing2){ return

  • How to understand the complexity of c and c type declaration 2010-03-26

    Reprinted Have come across you confused, like int * (* (* fp1) (int)) [10]; such a variable statement? This will be easy to difficult, step by step teach you how to understand this complex C / C statement. We will all encounter every day than the sim

  • Turn: on the C language pointer constant problem 2010-03-06

    const int * pi me first is that the semantics of const int * pi what is the role (of course, int const * pi is the same, we have said before, they actually are the same). See the following example: Code Start *************** //************* int i1 =

  • In-depth understanding of C language pointer mystery 2010-04-30

    Source: Pointer is a special variable that stores the value which is interpreted as a memory address. Need to figure out to figure out a pointer to a pointer of the four aspects: t

  • <An Introduction to Boost> Part I General Library scoped_ptr pointer 2010-07-17

    scoped_ptr Header: "boost / scoped_ptr.hpp" boost:: scoped_ptr used to ensure that the right to delete dynamically allocated objects. scoped_ptr with and std:: auto_ptr similar characteristics, but the biggest difference is that it can not be tr

  • C language null pointer. Null pointer constant. NULL & 0 2010-08-23

    1. What is a null pointer constant (null pointer constant)? [] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. Here to tell us: 0,0 L, '\ 0', 3 - 3,0 * 17 (they a

  • [Change] C + + reinterpret_cast, const_cast and other explicit type conversion summary 2010-09-13

    #include<iostream.h> int main(void) { //reinterpret_cast // One type into another type of pointer to a pointer, this pointer variable in the conversion does not modify the value of the data storage format // Just a pointer at compile time the type o

  • Super pointer study notes 2010-10-22

    Excerpts of others: C language pointer declaration of all the complex are formed by the various declarations nested. How to interpret the complex pointer Declaration? Both right-left rule is a well-known and commonly used method. However, the right-l

  • C # to C language and no type of object pointers 2010-10-27

    Life is always a lot of accidents, get the get the C # to make me engage in C language, this is not a degradation of what, but after a period of learning, discovery, C language really is super strong, the main problem is that it is too simple , the s

  • Function pointer with the pointer function 2010-11-03

    Suppose a pointer to a int variable, int variable which holds the address stored in memory, the same function have the address, this is because the function of the machine language Loaded into memory by the code component, pointer to a function with

  • string, char *, int type conversion, c + + forced into 2011-01-10

    A, The following are several types of commonly used conversion between each other string Turn int .............................. char* Turn int #include <stdlib.h> int atoi(const char *nptr); long atol(const char *nptr); long long atoll(const char *

  • Chapter II pointer to pointer to allocate and free space (transfer) 2011-05-08

    Loaded <vernacular c + +>: 20.1 Understanding pointers two "change" 20.1.1 change the pointer value 20.1.2 change the value of a variable pointer 20.1.3 two change? A change? 20.2 C + + memory allocatio

  • On the Object Pascal pointer 2011-05-03

    Everyone thinks, C language were strong, and its freedom, it is most reflected in its flexible use of the pointer. Therefore, that the pointer is C language of the soul, no exaggeration. At the same time, this argument is also misleading to many peop

  • C language pointer (b) 2011-05-11

    Array pointer and the pointer to the array variable C language requirements: If the pointer variable p is pointing to an element of the array, the p +1 points to the same the next element in the array, because array name in the C language, the first

  • jsp built-in objects 2010-07-23

    JSP includes nine built-in objects (hidden object): A built-in object is the default jsp page object can be used directly without pre-stated. 2 jsp pages _jspService () method automatically instantiate a variety of built-in objects. Built-in objects