source: cprs/trunk/VA/VA2006Utils.pas@ 973

Last change on this file since 973 was 829, checked in by Kevin Toppenberg, 14 years ago

Upgrade to version 27

File size: 2.0 KB
Line 
1unit VA2006Utils;
2
3interface
4
5uses
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
10procedure FixHeaderControlDelphi2006Bug(HeaderControl: THeaderControl);
11
12implementation
13
14uses
15 VAUtils;
16
17type
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
28procedure THeaderControl2006BugFixer.HeaderControlMessageHandler
29 (var Msg: TMessage; var Handled: Boolean);
30var
31 OnSectionClick: TSectionNotifyEvent;
32begin
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;
41end;
42
43procedure THeaderControl2006BugFixer.Notification(AComponent: TComponent;
44 Operation: TOperation);
45begin
46 inherited;
47 if (Operation = opRemove) and (AComponent = FHeaderControl) then
48 begin
49 RemoveMessageHandler(FHeaderControl, HeaderControlMessageHandler);
50 Self.Free;
51 end;
52end;
53
54constructor THeaderControl2006BugFixer.CreateWrapper(HeaderControl: THeaderControl);
55begin
56 inherited Create(nil);
57 FHeaderControl := HeaderControl;
58 FHeaderControl.FreeNotification(HeaderControl);
59 AddMessageHandler(HeaderControl, HeaderControlMessageHandler);
60end;
61
62procedure FixHeaderControlDelphi2006Bug(HeaderControl: THeaderControl);
63begin
64 THeaderControl2006BugFixer.CreateWrapper(HeaderControl);
65end;
66
67end.
Note: See TracBrowser for help on using the repository browser.