This example obtains a list of heap handles for the current process by using the Getprocessheaps function before and after establishing a new heap.
:
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;typeTForm1=class(tform) Memo1:tmemo; Memo2:tmemo; Button1:tbutton; procedureformcreate (Sender:tobject); procedureButton1Click (Sender:tobject); End;varForm1:tform1;Implementation{$R *.DFM}{extract the common parts of the following two processes as a separate process}proceduregetheaps (list:tstrings);varHeaparr:Array[0..9] ofThandle;{for a list of arrays, first assume that there are 10 heaps}N:integer; I:integer;begin {gets the list of heaps in the process, parameter 1 of the function is the array size, parameter 2 is the first element of the array, returns the actual number of heaps}N:= Getprocessheaps (Length (Heaparr), heaparr[0]); List.add (Format ('There are%d heaps in the current process', [n])); List.add ('their handles are:'); forI: =0 toN-1 DoList.add (IntToStr (heaparr[i));End;proceduretform1.formcreate (sender:tobject);beginmemo1.clear; {calling a public procedure to display a list of heap handles in Memo1}getheaps (Memo1.lines); {add a handle to the default heap again}Memo1.Lines.Add ("'); MEMO1.LINES.ADD ('the handle to the default heap is:'); MEMO1.LINES.ADD (IntToStr (GetProcessHeap));End;procedureTform1.button1click (sender:tobject);varMyheap:thandle;begin {Create a new heap}Myheap:= HeapCreate (0,1024x768*1024x768*2,0);{build a heap of 2M}memo2.clear; {calling a public procedure to display a list of heap handles in Memo2}getheaps (Memo2.lines); {add a handle to the new heap again}Memo2.Lines.Add ("'); MEMO2.LINES.ADD ('the handle to the new heap is:'); MEMO2.LINES.ADD (IntToStr (myheap)); {destroying the new heap}HeapDestroy (myheap);End;End.
Delphi7 (v)