[829] | 1 | unit VA2006Utils;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Classes, Controls, ComCtrls, CommCtrl;
|
---|
| 7 |
|
---|
| 8 | // Fixes bug in Delphi 2006, where clicking on a header control section after
|
---|
| 9 | // any other section have been added or deleted could cause access violations
|
---|
| 10 | procedure FixHeaderControlDelphi2006Bug(HeaderControl: THeaderControl);
|
---|
| 11 |
|
---|
| 12 | implementation
|
---|
| 13 |
|
---|
| 14 | uses
|
---|
| 15 | VAUtils;
|
---|
| 16 |
|
---|
| 17 | type
|
---|
| 18 | THeaderControl2006BugFixer = class(TComponent)
|
---|
| 19 | private
|
---|
| 20 | FHeaderControl: THeaderControl;
|
---|
| 21 | procedure HeaderControlMessageHandler(var Msg: TMessage; var Handled: Boolean);
|
---|
| 22 | protected
|
---|
| 23 | procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
---|
| 24 | public
|
---|
| 25 | constructor CreateWrapper(HeaderControl: THeaderControl);
|
---|
| 26 | end;
|
---|
| 27 |
|
---|
| 28 | procedure THeaderControl2006BugFixer.HeaderControlMessageHandler
|
---|
| 29 | (var Msg: TMessage; var Handled: Boolean);
|
---|
| 30 | var
|
---|
| 31 | OnSectionClick: TSectionNotifyEvent;
|
---|
| 32 | begin
|
---|
| 33 | if (Msg.Msg = CN_NOTIFY) and (PHDNotify(Msg.LParam)^.Hdr.code = HDN_ITEMCLICK) then
|
---|
| 34 | begin
|
---|
| 35 | Handled := TRUE;
|
---|
| 36 | Msg.Result := 0;
|
---|
| 37 | OnSectionClick := FHeaderControl.OnSectionClick;
|
---|
| 38 | if assigned(OnSectionClick) then
|
---|
| 39 | OnSectionClick(FHeaderControl, FHeaderControl.Sections[PHDNotify(Msg.lParam)^.Item]);
|
---|
| 40 | end;
|
---|
| 41 | end;
|
---|
| 42 |
|
---|
| 43 | procedure THeaderControl2006BugFixer.Notification(AComponent: TComponent;
|
---|
| 44 | Operation: TOperation);
|
---|
| 45 | begin
|
---|
| 46 | inherited;
|
---|
| 47 | if (Operation = opRemove) and (AComponent = FHeaderControl) then
|
---|
| 48 | begin
|
---|
| 49 | RemoveMessageHandler(FHeaderControl, HeaderControlMessageHandler);
|
---|
| 50 | Self.Free;
|
---|
| 51 | end;
|
---|
| 52 | end;
|
---|
| 53 |
|
---|
| 54 | constructor THeaderControl2006BugFixer.CreateWrapper(HeaderControl: THeaderControl);
|
---|
| 55 | begin
|
---|
| 56 | inherited Create(nil);
|
---|
| 57 | FHeaderControl := HeaderControl;
|
---|
| 58 | FHeaderControl.FreeNotification(HeaderControl);
|
---|
| 59 | AddMessageHandler(HeaderControl, HeaderControlMessageHandler);
|
---|
| 60 | end;
|
---|
| 61 |
|
---|
| 62 | procedure FixHeaderControlDelphi2006Bug(HeaderControl: THeaderControl);
|
---|
| 63 | begin
|
---|
| 64 | THeaderControl2006BugFixer.CreateWrapper(HeaderControl);
|
---|
| 65 | end;
|
---|
| 66 |
|
---|
| 67 | end.
|
---|