Menu

Record as TagObject

Help
DaveW
2019-06-13
2019-06-14
  • DaveW

    DaveW - 2019-06-13

    I would like to store some extra text and numerical data in some GLScene HeightFields, for example datetime stamp, modified by name, a 2D array of Z values, etc. It seems to me that this should be possible using (something equivalent to) a record attached to the .TagObject however I can't work out how I should define the 'record' as an object and then how I can access the data.

    1. Is this a sensible approach? Is there a better way?
    2. How should I define the record/object, create the object & assign it to the HeightField, access the data.

    David W

     
  • Jerome.D (BeanzMaster)

    Hi Dave the better is instead of record is using a class and assign it to the tagobject. But becareful

    Type
      TMyRecordClass = Class(TGLUpdatableObject) // or simply TObject
      private
        FData1 : Byte
        FData2 : Word
        etc....
       public
         Constructor Create; override;
         Desctructor Destroy;
         property Data1 : Byte Read FData1 write FData1
            etc....
        end;
    
    In your code, for adding extra infos
    
           MyObjectData := TMyRecordClass.Create;
           MyObjectData.Data1 := 123;
            MyHeightFielad.TagObject := MyObjectData
    

    Take care before close your form, you'll need traverse thë GLScene and free your "TMyRecordClass" objects yourself. Because actually Object and scene haven't got event "OnfreeObject" (it will be a good feature)

    So in Form' CloseQuery event or similar you'll must do call a (recursive) freeing function like this, from scratch :

    procedure TForm1.FreeTagObject(anObject : TGLBaseSceneObject);
    Var
      i : Integer;
      TmpObject : TGLBaseSceneObject;
    begin
      if anObject.count>0 then
      begin
        For i:=0 to anObject.Count-1 do
        begin
          TmpObject := GLScene1.Objects[i];
          if anObject.HasSubChildren then FreeTagObject(TmpObject);
          if assigned(TmpObject.TagObject) then
          begin
            TMyRecordClass(TmpObject.TagObject).Free;
            TmpObject.TagObject := nil;
          end;
        end;
      end;
    end; 
    
    procedure TForm1.FormCloseQuery(Sender : TObject; var CanClose : boolean);
    begin
      FreeTagObject(GLScene1.Objects);
    end;
    

    In hope this could help you

    Cheers

     

    Last edit: Jerome.D (BeanzMaster) 2019-06-14
  • DaveW

    DaveW - 2019-06-14

    Hi Jerome,
    Thank you for the help! I will give it a try...
    David.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.