Jump to content

AlanScottAgain

Members
  • Content Count

    37
  • Joined

  • Last visited

Everything posted by AlanScottAgain

  1. I know I should have done it sooner - I've been putting it off too long. Thanks to PB for giving me a push to do this, in another tread. So I've stripped down my TDrawingObject and TDrawingObjectList Classes to show what I have and what I'm trying to acheive : Type TDrawingObjectType = (doChild, doBackground); TDrawingObjectsList = Class; //Forward Declaration TDrawingObject = Class Private FObjectType: TDrawingObjectType; FDrawingObjectsList: TDrawingObjectsList; Public Constructor Create(AObjectType: TDrawingObjectType); Destructor Destroy; Property ObjectType: TDrawingObjectType Read FObjectType Write FObjectType; Property DrawingObjectsList: TDrawingObjectsList Read FDrawingObjectsList Write FDrawingObjectsList; End; TDrawingObjectsList = Class(TObjectList<TDrawingObject>) Private FOwnsObjects: Boolean; Protected Function GetItem(Index: Integer): TDrawingObject; Procedure SetItem(Index: Integer; AObject: TDrawingObject); Public Procedure Draw(ACanvas: IskCanvas); Property OwnsObjects: Boolean Read FOwnsObjects Write FOwnsObjects; Property Items[Index: Integer]: TDrawingObject Read GetItem Write SetItem; default; Procedure LoadDrawingObjects; End; I'm trying to implement interfaces for these objects The code below looks pretty good at least I don't a lot of errors: I have two main questions at the moment: In the TDrawingListClass declaration I used to have TDrawingObjectsList = Class(TObjectList<TDrawingObject>) to type cast the list. How do I achieve the same with the class/interface declaration? TDrawingObjectsList = class(TInterfacedObject, IDrawingObjectList, TObjectList<TDrawingObject>) is not right. In the class constructs I have kept the interface references eg: property DrawingObjectList: IDrawingObjectList read GetDrawingObjectList write SetDrawingObjectList; Is this correct? type TDrawingObjectType = (doChild, doBackground); IDrawingObjectList = interface; // forward declaration IDrawingObject = interface(IInterface) ['{A8701C68-51FC-4087-8C30-E3CA4C7C1D8E}'] function GetDrawingObjectType: TDrawingObjectType; procedure SetDrawingObjectType(ADrawingObjectType: TDrawingObjectType); function GetDrawingObjectList: IDrawingObjectList; procedure SetDrawingObjectList(ADrawingObjectList: IDrawingObjectList); property ObjectType: TDrawingObjectType read GetDrawingObjectType write SetDrawingObjectType; property DrawingObjectList: IDrawingObjectList read GetDrawingObjectList write SetDrawingObjectList; end; TDrawingObject = class(TInterfacedObject, IDrawingObject) function GetDrawingObjectType: TDrawingObjectType; procedure SetDrawingObjectType(ADrawingObjectType: TDrawingObjectType); function GetDrawingObjectList: IDrawingObjectList; procedure SetDrawingObjectList(ADrawingObjectList: IDrawingObjectList); property ObjectType: TDrawingObjectType read GetDrawingObjectType write SetDrawingObjectType; property DrawingObjectList: IDrawingObjectList read GetDrawingObjectList write SetDrawingObjectList; end; IDrawingObjectList = interface(IInterface) ['{9D2C916D-19F0-49B2-93C6-B84592442057}'] Private function GetOwnsObject: Boolean; procedure SetOwnsObject(AOwnsObject: Boolean); property OwnsObjects: Boolean read GetOwnsObject write SetOwnsObject; function GetItem(Index: Integer): IDrawingObject; procedure SetItem(Index: Integer; AObject: IDrawingObject); Public Constructor Create(AObjectType: TDrawingObjectType); Destructor Destroy; property Items[Index: Integer]: IDrawingObject read GetItem Write SetItem; procedure Draw(ACanvas: ISkCanvas); procedure LoadDrawingObjects; end; TDrawingObjectsList = class(TInterfacedObject, IDrawingObjectList) private FOwnsObjects: Boolean; function GetOwnsObject: Boolean; procedure SetOwnsObject(AOwnsObject: Boolean); property OwnsObjects: Boolean read GetOwnsObject write SetOwnsObject; function GetItem(Index: Integer): IDrawingObject; procedure SetItem(Index: Integer; AObject: IDrawingObject); public property Items[Index: Integer]: IDrawingObject read GetItem write SetItem; procedure Draw(ACanvas: ISkCanvas); procedure LoadDrawingObjects; end; Thanks Alan
  2. AlanScottAgain

    Interfaces - Time to face my ignorance.

    Thanks for all the feedback. I think that interfaces at this stage is overkill. As a result of the comments I have cleaned up the code and taken the advice on object lifetime and ownership.
  3. AlanScottAgain

    Do I need to free list

    Hi I have an object that holds a TObjectList. I have a helper class that builds The objects that go into the TObjectList. Currently I just Assign the helper ObjectList to the RootObjectList. RootObject.ObjectsList := Helper.DrawingObjectsList; I was wondering if I should Free the RootObjectList - if it has objects - before I assign the new list? Otherwise what happens to the old possibly orphaned list? Does the compilers take care of it? I have OwnsObjects set to True. Thanks Alan
  4. AlanScottAgain

    Do I need to free list

    Thanks for both for the answers. I had a feeling I was getting into trouble. I like the idea of passing the list to the helper object - its simple. Even though I have dabbled in Delphi for a long time I really don't understand interfaces. But it's a good time to learn. Once again thanks. Alan
  5. Hi I don't understand why I'm getting this message: This a cut down version of my object. TDrawingObject = class private FObjectType: TDrawingObjectType; FBoundsRect: TRectF; FTag: Integer; public constructor Create(AObjectType: TDrawingObjectType); destructor Destroy; property ObjectType: TDrawingObjectType read FObjectType write FObjectType; property BoundsRect: TRectF read FBoundsRect write FBoundsRect; property Tag: Integer read FTag write FTag default 0; end; Then in procedure: var TempDrawingObject: TDrawingObject; begin TempDrawingObject:= TDrawingObject.Create; TempResult.BoundsRect.Top:= 20; TempResult.Tag:= 5; end; I can not assign 20 to the BoundsRect.top Property. But I can assign to the Tag property. Do I need to create a setter? What have I missed. Many thanks for your advice. Alan
  6. AlanScottAgain

    Left side cannot be assigned to

    So for simple cases don't bother with a property? Only when you need a getter/setter?
  7. AlanScottAgain

    Left side cannot be assigned to

    Thank you for the clear explanation.
  8. Hi I was wondering what the best way to approach this is? Scenario: I'm creating a simple drawing program based on Skia (Which is awesome) I want to be able to create compound shapes. My air code: TDrawingObject= class Brush color path location end; Then TDrawingObjectList = class (TObjectList<TDrawingObject>) Holds and access the TDrawingObjects How could I create something like: TDrawingObject= class Brush color path location DrawingObjectList end; So that I can recursively run through the one object that is made up of multiples of itself? Thanks Alan
  9. Thank you I did not know about forward declarations 👍
  10. But then its an untyped list? I guess that may be the way to go
  11. Thanks How do I get past the issue that TDrawingObjectList is not declared until after TDrawingObject? So DrawingObject can't hold a list of DrawingObjectList TDrawingObjectList can hold more TDrawingObjectList(s) I feel Like I'm missing something basic! I can used an untyped list but that defeats the object. I guess the question is how do I declare/ structure a recursive list.
  12. Hey Just a quick hello and to say I had a lot of problems trying to register. Tried using alan at urbanhealth.com.au several times, never received the confirmation email, even after a few days. Just got it working with an old UK email. Not sure if others have had similar problems? Now I'm registered is there a way to remove the Again from my username? I used Alan & AlanScott trying to register before. Thanks Alan
×