I haven't created a class since my Dephi days 12 years ago.
So, just for the exercise, I thought I'd create a TRect variant from scratch and not using TRect as a ParentClass.
My Trect (TMyTrect) has anchor points (None, the 4 corners, and Centre).
All coded and a tester to test the correctness of the code within the class (280000 tests).
Then I thought Pens & Brushes are always associated with Rects, so I add a creation of them within MyRect.
Assigning a colour to both proved they were created OK, and destruction worked.
All good. All working.
I then decided to try out TMyRect in a form.
MyRect.Brush:=Form1.Canvas.Brush;
MyRect.Pen:=Form1.Canvas.Pen;
Both worked OK, but when Form1 was closed (deploying the Destructor) an exception error occured.
A search provided no clue.
By chance I included in Form1.Close the following:
MyRect.Brush:=nil;
MyRect.Pen:=nil;
That prevented the error on Close, so I moved that code to the Destructor:
destructor TMyRect.Free;
begin
Brush:=nil;
Pen:=nil;
Brush.Free;
Pen.Free;
end;
... and that worked.
So I've found the solution, but still do not understand the problem.Without too heavy an explanation, can someone please tell me the problem?
Thanks,
Bazza