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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 ImageEnVect Object MyData Multiple String Issues

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
andyhill Posted - Mar 24 2017 : 02:32:20
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
4   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Mar 29 2017 : 00:58:49
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
andyhill Posted - Mar 26 2017 : 05:51:15
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
xequte Posted - Mar 25 2017 : 20:56:27
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
andyhill Posted - Mar 24 2017 : 22:54:39
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