System.tptrwrapper: Pointer Wrapper

Source: Internet
Author: User
Tags integer wrapper

When the System unit has a tptrwrapper structure, it provides a very small function: a pointer (pointer) and a pointer address (nativeint) conversion. Obviously, the previously used Integer (p) or PTR (number) has been After not applicable with 64-bit, then use tptrwrapper should be more convenient and more insurance option. Found in the new source Delphi, almost the tptrwrapper as a pointer to use.

{Tptrwrapper fully functional test}procedure tform1.formcreate (sender:tobject);
var
  num:integer;
  P:pointer;
  Address:nativeint;
  Pw1,pw2,pw3:tptrwrapper;
  B:boolean;
Begin
  P: = @num;
 
  Establishment Method 1
  PW1: = Tptrwrapper.create (p);
  Address: = PW1. Tointeger;           Tointeger
 
  //Establishment Method 2
  PW2: = tptrwrapper.create (address);
  Pinteger (PW2. ToPointer) ^: = 123;    ToPointer
  showmessage (inttostr (num));//123
 
  //Establish Method 3
  PW3: = Tptrwrapper.nilvalue;
 
  Equal operation
  B: = PW1 = PW2;
  ShowMessage (Booltostr (b, True));
 
  NotEqual operation
  B: = PW1 <> PW3;
  ShowMessage (Booltostr (b, True));
 
  As the structure of the tptrwrapper, its starting position is stored in the pointer
  p: = pointer (PW1);
  ShowMessage (IntToStr (Pinteger (p) ^)); 123
 
  //Even so, you can directly convert a number of addresses, or pointers directly to Tptrwrapper
  PW3: = Tptrwrapper (address);
  ShowMessage (IntToStr (PW3)); similar to 1244823end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.