ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 ImageEnVect Object MyData Multiple String Issues
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

andyhill

Australia
133 Posts

Posted - Mar 24 2017 :  02:32:20  Show Profile  Reply
Hi, I have implemented MyData as follows (I have several hundred objects, at any time, do I need to FreeMem(MyData, SizeOf(TMyData)); ?:-


type
  TMyData = record
    Group: Integer;
    Name: String[100];        // Works
    Description: String[255]; // Fails
    Tag: Boolean;
  end;
  PMyData = ^TMyData;

...

  ihObj:= ievFront.AddNewObject;
  ievFront.ObjKind[ihObj]:= iekPOLYLINE;
  ievFront.ObjBrushStyle[ihobj]:= bsSolid;
  ievFront.ObjBrushColor[ihobj]:= clRed;
  ievFront.ObjPenWidth[ihObj]:= 1;
  ievFront.ObjPenColor[ihObj]:= clBlack;
  ievFront.ObjStyle[ihObj]:= [ievsVisible, ievsSelectable, ievsSizeable];
  ievFront.OffScreenPaint:= True;
  ievFront.PolylineClosingMode:= iecmAlways;
  ievFront.SetObjPolylinePoints(ihObj, MyPointsArray);
  ievFront.ObjPolylineClosed[ihObj]:= True;
  GetMem(MyData, SizeOf(TMyData)); 
  MyData^.Group:= 0;
  MyData^.Name:= IntToStr(ihObj)+#0;        // Tried With and Without #0
  MyData^.Description:= 'Does Not Work'+#0; // Tried With and Without #0
  ievFront.ObjUserData[ihObj]:= MyData;
  ievFront.ObjUserDataLength[ihObj]:= SizeOf(TMyData);
  // If I free here (FreeMem(MyData, SizeOf(TMyData));) we get errors

...

procedure TfMain.ievFrontObjectOver(Sender: TObject; hobj: Integer);
var
  s: String;
begin
  StatusBar1.Panels[1].Text:= '';
  if hobj = 152  then begin
    s:= 'debug';
  end;
  try
    MyFetchData:= ievFront.ObjUserData[hobj]; 
    if MyFetchData <> nil then begin
      // Description Always is '' // Tried MyFetchData^.Description too
      StatusBar1.Panels[1].Text:= MyFetchData.Description; 
    end;
  except
  end;
end;


Andy

andyhill

Australia
133 Posts

Posted - Mar 24 2017 :  22:54:39  Show Profile  Reply
I should have mentioned for MouseOver and ObjectOver events I did have MyFetchData as a global variable declared once in FormCreate with one only GetMem used (not shown above).

For my procedure where I add objects I have MyData declared locally. My question is when adding objects do we have to use GetMem on each addition, if so where do we free them, or can we just use the same GetMem on all objects ?



Andy
Go to Top of Page

xequte

38615 Posts

Posted - Mar 25 2017 :  20:56:27  Show Profile  Reply
Hi Andy

Don't free the object! you have passed ownership of it to the TImageEnVect, and it will take care of the freeing (if you do need to free it, then set ObjUserData to nil).

Yes, you need to create the memory for each ObjUserData you set.

Also, see the demo:
Demos\Annotations\UserDataVect



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

andyhill

Australia
133 Posts

Posted - Mar 26 2017 :  05:51:15  Show Profile  Reply
1) Can I still use the ONE global MyFetchData and reuse it over and over again with MyFetchData:= ievFront.ObjUserData[hobj]; for all of the MouseOver and ObjectOver events ?

2) How do I handle LARGE strings
type
TMyData = record
Group: Integer;
Name: String[100];
Description: String[4026]; ???
Tag: Boolean;
end;
PMyData = ^TMyData;



Andy
Go to Top of Page

xequte

38615 Posts

Posted - Mar 29 2017 :  00:58:49  Show Profile  Reply
Hi Andy

1. For all memory that you create, you need to free, just once. IOW, any pointer you pass to ObjUserData, ImageEn will free when the object is destroyed. You shouldn't pass the same pointer to multiple objects or ImageEn will try to free it multiply

2. Yes, that is one method. You could also store your strings in a stringlist and just store an index in your ObjUserData record.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: