451页
A reference(&) is like a constant pointer that is automatically dereferenced. It is usually used for function argument lists and functions return values. But you can also make a free-standing reference. For example
..................
..................
There are certain rules when using references:
1. A reference must be initialized when it is created.(Pointers can be initialized at any time).
2. Once a reference is initialized to an object, it cannot be changed to refer to another object.(Pointers can be pointed to another object at any time)
3. You cannot have NULL reference. You must always be able to assume that a reference is connected to a legitimate piece of storage.
Reference in functions
The most connon place you'll see references is as function arguments and return values. When a reference is used as a function argument, any modificaiton to the reference inside the function will cause changes to the argument outside the function. Of cource, you could do the same thing by passing a pointer, but a Reference has much cleaner syntax(You can think of a reference as nothing more than a syntax convenience, if you want.)
..............
太多了,就打这么多
//保存指针
Function FormatObjectVar(Obj : TObject):String;
var
P : pointer;
begin
P := Pointer(OBJ);
Result := Format('%p', [p]);
end;
然后直接保存字符串.
//根据地址引用那个对象
Function GetObj(ObjAddr : String):Tobject;
var
Tmp : TObject;
P : Dword;
S : String;
begin
Result := Nil;
S := Trim(ObjAddr);
try
P := strtoint('$'+S);
TMP := TObject(P);
S := Tmp.ClassName;
Result := Tmp;
except
end;
end;