(2)Me根本不懂OOP-----想读《D4技术内幕》么?follow me(25分)

  • 主题发起人 千中元
  • 开始时间
>>ThreadFunc(nil),nil是pointer???

To see how pointers work, look at the following example.

1 var

2 X, Y: Integer
// X and Y are Integer variables
3 P: ^Integer
// P points to an Integer
4 begin
5 X := 17
// assign a value to X
6 P := @X
// assign the address of X to P
7 Y := P^
// dereference P
assign the result to Y
8 end;

Line 2 declares X and Y as variables of type Integer. Line 3
declares P as a pointer to an Integer value
this means that P
can point to the location of X or Y. Line 5 assigns a value to X,
and line 6 assigns the address of X (denoted by @X) to P. Finally,
line 7 retrieves the value at the location pointed to by P (denoted
by ^P) and assigns it to Y. After this code executes, X and Y have
the same value, namely 17.

 
continue……

For example, the following code assigns data stored in a real variable to an integer variable.

type

PInteger = ^Integer;
var
R: Single;
I: Integer;
P: Pointer;
PI: PInteger;
begin
...
P := @R;
PI := PInteger(P);
I := PI^;
end;

Of course, reals and integers are stored in different formats.
This assignment simply copies raw binary data from R to I,
without converting it.
In addition to assigning the result of an @ operation, you can
use several standard routines to give a value to a pointer. The
New and GetMem procedures assign a memory address to an existing
pointer, while the Addr and Ptr functions return a pointer to a
specified address or variable.
Dereferenced pointers can be qualified and can function as
qualifiers, as in the expression P1^.Data^.

The reserved word nil is a special constant that can be assigned to
any pointer. When nil is assigned to a pointer, the pointer doesn't
reference anything.
 
分不多,意思意思:}
 

Similar threads

I
回复
0
查看
635
import
I
I
回复
0
查看
707
import
I
I
回复
0
查看
700
import
I
I
回复
0
查看
581
import
I
顶部