DemoForm.pas 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. unit DemoForm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, FastMMDebugSupport, StdCtrls;
  6. type
  7. TForm1 = class(TForm)
  8. Button1: TButton;
  9. Button2: TButton;
  10. Button3: TButton;
  11. procedure Button3Click(Sender: TObject);
  12. procedure Button2Click(Sender: TObject);
  13. procedure Button1Click(Sender: TObject);
  14. private
  15. { Private declarations }
  16. public
  17. { Public declarations }
  18. end;
  19. var
  20. Form1: TForm1;
  21. implementation
  22. {$R *.dfm}
  23. procedure TForm1.Button1Click(Sender: TObject);
  24. begin
  25. TObject.Create;
  26. end;
  27. procedure TForm1.Button2Click(Sender: TObject);
  28. var
  29. x, y, z: TObject;
  30. begin
  31. {Set the allocation group to 1}
  32. PushAllocationGroup(1);
  33. {Allocate an object}
  34. x := TPersistent.Create;
  35. {Set the allocation group to 2}
  36. PushAllocationGroup(2);
  37. {Allocate a TControl}
  38. y := TControl.Create(nil);
  39. {Go back to allocation group 1}
  40. PopAllocationGroup;
  41. {Allocate a TWinControl}
  42. z := TWinControl.Create(nil);
  43. {Pop the last group off the stack}
  44. PopAllocationGroup;
  45. {Specify the name of the log file}
  46. SetMMLogFileName('AllocationGroupTest.log');
  47. {Log all live blocks in groups 1 and 2}
  48. LogAllocatedBlocksToFile(1, 2);
  49. {Restore the default log file name}
  50. SetMMLogFileName(nil);
  51. {Free all the objects}
  52. x.Free;
  53. y.Free;
  54. z.Free;
  55. {Done}
  56. ShowMessage('Allocation detail logged to file.');
  57. end;
  58. procedure TForm1.Button3Click(Sender: TObject);
  59. begin
  60. with TObject.Create do
  61. begin
  62. Free;
  63. Free;
  64. end;
  65. end;
  66. end.