HeapChk 0.91 - Test blocks on heap
==================================

This is the second (beta-) version of a utility for Delphi.
Test it and write your comments.

HeapChk does:
  - store every allocation and deallocation of heapmemory.
  - add two extra bytes on the end of each block. This bytes
    contains a testpattern to check for blockoverflow.
  - you can check the heap with the function HeapTestCheckPtrs.
    you get a message for every blockoverflow with the sourcecode
    where the block was allocated.
  - on program-exit you get a file (normaly DUMP.TXT) with a list
    of every non-deallocated block.

How to use it.
  1. !!! Switch Option/Project/Linker/Mapfile to 'detailed' !!!
     !!! and    Option/Project/Compiler/Debuginfos to 'ON'  !!!

  2. Insert 'HeapChk' in the uses-statement of the projectfile (*.DPR)

  3. Make a testbutton in a form.
     in testbutton-OnClick write the line
        HeapTestCheckPtrs;
     and in the uses-statement of the Form insert 'HeapTest';

  4. Click the button and the check is done.

There is a Testproject (HEAP.* und HAEPTST.*) for more features.

Unit HEAPCHK
============
you should insert this Unit as the first Unit in the DPR-File

  var HeapCheckActive : boolean;
     True, when HeapChk was installed. If this variable is False
     you have probably a wrong Delphi-Version. It patched WMEM.OBJ
     on runtime and checked the code before.

  procedure HeapLogOff;
     switch Heap-Logging off. No registration of any allocation or deallocation

  procedure HeapLogOn;
     switch Heap-Logging on

  !!! New !!!
  procedure HeapTestClear;
     clears the internal list of allocated blocks. This procedure should be
     called in the DPR-File after the 'begin'-statement.
     The result is a cleaner DUMP.TXT because blocks allocated by the RTL
     on startup wouldn't be listed. Look in the example.


Unit HEAPTEST
=============
you should insert this Unit in your project.

  var HeapTestSearchPath : string;
     Searchpath for sourcefiles. HEAPTEST use this path to display the
     source in the HeapTestCheckPtrs-Dialog.

  var HeapTestDumpFile   : string;
     Name and path of the Dumpfile after programm-execution.
     Default is 'DUMP.TXT';
     When this string is empty, no Dumpfile will be generated.

  function  HeapTestCheckPtr( var pt : pointer) : integer;
     Test a single pointer.
     Results:
        HEAPCHECK_OKAY     = 1   ( block Okay )
        HEAPCHECK_OVERFLOW = 2   ( someone have written to much )
        HEAPCHECK_NOTFOUND = 3   ( block dosn't exist on heap )

  function  HeapTestCheckPtrs                   : integer;
     Test all blocks on heap.
     Result:
        HEAPCHECK_OKAY     = 1   ( all blocks Okay )
        HEAPCHECK_OVERFLOW = 2   ( one or more blocks overflowed )
                                 for every pointer a dialog pops up and
                                 show the callstack at allocation-time
                                 (when there are debug-infos)

  procedure HeapTestShowPtrs; far;
     writes the DUMP.TXT. This procedure will execute automaticly on
     program-exit.

thats all.
I hope, you understand my english.

this is a betaversion for testing. Use it on your own risk. I haven't decide
what to do with it. Maybe I put it in public domain, shareware etc, when the
first golden code is ready.

Version 0.91
============
new features:
-- procedure HeapTestClear;
   look in the example

-- optimized for speed (much!)

-- version 0.90 needs a component 'BorderPanel' that was not included.
   This referenz is removed.

-- some minor bugfixes

shareware-version
=================
I'm currently work on a sharewareversion with more features. Look at the
example and the dumpfile 'SHAREWAR.DMP' for features implemented yet.

features of the sharewareversion:
  -- Log all overflows in the DUMP-File. The trial-version checks only blocks
     that exist at check-time, and ignors blocks, that was deallocated
     before the check. This blocks will be listed in the DUMP-File.

  -- Shows the maximum of stack, local heap and heapmemory.

  -- utility to view the dumpfile with sourcecode.

  -- utility to configure the heaptest. You can exclude units (eg classes)
     in the stack-trace.

  -- the sharewareverison will include the BorderPanel-componentas a free gift.
     this component is a panel with inner and outer borders. (put a memofield
     with no border in a panel, set the align of the memo to alClient, and you
     see the reason for such a component)

  -- more features will be included.

  If you are interested in the shareware-version, please contact me.



write comments to
  Frank Mertsch - Roger Nelke
  CS-ID 100024, 2711


Happy bugging
  roger







