This example is based on the getmem example:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formcreate (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} type tmyrec = record {definition structure; remember that the size of this structure is 12 bytes} Name: String [8]; age: word; {although word is 2 bytes; however, because it is 4-byte aligned, it occupies 4 bytes} end; pmyrec = ^ tmyrec; {definition structure pointer} var PR: pmyrec; Procedure tform1.fo Rmcreate (Sender: tobject); const STR = 'address: % d; Name: % s'; begin {apply for memory of 3 tmyrec structures} // getmem (PR, sizeof (tmyrec) * 3); reallocmem (PR, sizeof (tmyrec) * 3); {This sentence can also be replaced by a previous line} {value} PR. name: = 'zhang san'; PR. age: = 11; Inc (PR); PR. name: = 'Li si'; PR. age: = 22; Inc (PR); PR. name: = 'wang 5'; PR. age: = 33; {display the addresses and information of the three structures; the addresses should be consecutive (12 bytes)} Dec (PR, 2); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 15278504; Name: James} Inc (PR); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 15278516; Name: Li Si} Inc (PR); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 15278528; Name: Wang Wu} {re-apply for memory, requires five structure sizes, and assigns two new structures} Dec (PR, 2); reallocmem (PR, sizeof (tmyrec) * 5); Inc (PR, 3); PR. name: = 'ma 6'; PR. age: = 44; Inc (PR); PR. name: = 'Sun 7'; PR. age: = 55; {displays the relevant information. Although the address is continuous, it is already different from the above !} Dec (PR, 4); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 14875920; Name: Zhang San} Inc (PR); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 14875932; Name: Li Si} Inc (PR); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 14875944; Name: Wang Wu} Inc (PR); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 14875956; Name: Ma 6} Inc (PR); showmessage (format (STR, [INTEGER (PR), Pr. name]); {address: 14875968; Name: Sun Qi} Dec (PR, 4); freemem (PR, sizeof (tmyrec) * 5 ); {You can also use freemem to clear the memory applied by reallocmem} end; end.
Public Function directory under System Unit