Hello,

I'm writing an article about docking in Lazarus.

The first - and most simple - example I tried, failed:
- Drop a panel on a form
- Set dragkind to dkDock
- Set dragmode to dkAutomatic.
- Run application
- Drag panel outside form, and let go.

expected behaviour: a small form should appear, and the panel should be on it.

Actual behaviour: 4 Access violations (fix one to get to the next ;) ).

Attached small patch fixes the 4 access violations, after which the expected behaviour occurs. They are all checks to see if a object pointer is not-nil.

Better would be to fix the root of the problem:
I think the automatic creation of a dockhost form probably uses createnew(), 
which
maybe doesn't correctly allocate all structures (scrollbars/icons). But that is 
just
a wild guess, which I currently don't have time to investigate.

Michael.
Index: include/customform.inc
===================================================================
--- include/customform.inc	(revision 24391)
+++ include/customform.inc	(working copy)
@@ -292,7 +292,7 @@
   OldChange: TNotifyEvent;
   OldCurrent: Integer;
 begin
-  if not FIcon.Empty then
+  if Assigned(FIcon) and not FIcon.Empty then
   begin
     if FBigIconHandle = 0 then
     begin
@@ -319,7 +319,7 @@
   OldChange: TNotifyEvent;
   OldCurrent: Integer;
 begin
-  if not FIcon.Empty then
+  if Assigned(FIcon) and not FIcon.Empty then
   begin
     if FSmallIconHandle = 0 then
     begin
Index: include/scrollingwincontrol.inc
===================================================================
--- include/scrollingwincontrol.inc	(revision 24391)
+++ include/scrollingwincontrol.inc	(working copy)
@@ -61,9 +61,9 @@
   {if (FHorzScrollBar.Range>Result.Right)
   or (FVertScrollBar.Range>Result.Bottom) then
     DebugLn(['TScrollingWinControl.GetLogicalClientRect Client=',ClientWidth,'x',ClientHeight,' Ranges=',FHorzScrollBar.Range,'x',FVertScrollBar.Range]);}
-  if (FHorzScrollBar.Range > Result.Right) then
+  if Assigned(FHorzScrollBar) and (FHorzScrollBar.Range > Result.Right) then
     Result.Right := FHorzScrollBar.Range;
-  if (FVertScrollBar.Range > Result.Bottom) then
+  if Assigned(FVertScrollBar) and (FVertScrollBar.Range > Result.Bottom) then
     Result.Bottom := FVertScrollBar.Range;
 end;
 
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to