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 ObjectUserData Unicode Issue
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

andyhill

Australia
133 Posts

Posted - May 24 2017 :  20:31:55  Show Profile  Reply
I have been using code given to me by Nigel that works fine with non Unicode text.

My problem is I want to use Unicode text and it appears that the whole pointer concept fails to work with Unicode.

Please advise - Thanks in advance.

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

…

MyFetchData: PMyData;
MyDataArray: array of PMyData;

…

GetMem(MyFetchData, SizeOf(TMyData)); // Freed by me on close

…

  SetLength(MyDataArray, Length(MyDataArray)+1); // Set to zero length by me on close
  GetMem(MyDataArray[High(MyDataArray)], SizeOf(TMyData)); // Auto-Freed by ImageEn
  MyDataArray[High(MyDataArray)]^.Group:= 0;
  MyDataArray[High(MyDataArray)]^.Name:= IntToStr(ihObj);
  MyDataArray[High(MyDataArray)]^.Description:= '';
  ievFront.ObjUserData[ihObj]:= MyDataArray[High(MyDataArray)];
  ievFront.ObjUserDataLength[ihObj]:= SizeOf(TMyData);

…

MyFetchData:= ievFront.ObjUserData[hobj];

MyFetchData.Description returns ????????????????????????????????????????????????????????????


Andy

xequte

38180 Posts

Posted - May 25 2017 :  06:11:40  Show Profile  Reply
Hi Andy

Why are you creating MyFetchData? It does not need to be created if you are just reading from memory as here:

MyFetchData := ievFront.ObjUserData[hobj];

Also, what is the purpose of MyDataArray?

Your code should be something like:

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

…
var
  MyData: PMyData; 
begin
  GetMem(MyData, SizeOf(TMyData)); // Auto-Freed by ImageEn
  MyData^.Group:= 0;
  MyData^.Name:= IntToStr(ihObj);
  MyData^.Description:= '';
  ievFront.ObjUserData[ihObj]:= MyData;
  ievFront.ObjUserDataLength[ihObj]:= SizeOf(TMyData);

…
var
  MyFetchData: PMyData; 
begin
  MyFetchData:= ievFront.ObjUserData[hobj];
  ShowMessage( MyFetchData^.Description );


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

andyhill

Australia
133 Posts

Posted - May 25 2017 :  21:53:00  Show Profile  Reply
Nigel, I have about 3000 Polygon Objects each with their own ObjUserData, that is why I used an array so that the memory locations would not be merged, I will drop the array as you indicate this will not be a problem.

I need to handle Unicode which you have not addressed.

The very fact that you use a byte counter for your strings (String[255]) to me makes me think it uses bytes not Unicode WideChars. That is why we get ? as one byte cannot represent a Unicode WideChar.

Please show me how to work with Unicode in ObjUserData.

Andy
Go to Top of Page

xequte

38180 Posts

Posted - May 28 2017 :  15:32:08  Show Profile  Reply
Hi Andy

Every call to GetMem will return a unique block of memory, so the array is not needed.

However you are correct about String[255], as that will actually give you an Ansi string. Try replacing it with a fixed array of (Unicode) chars, e.g

Description: array[0..254] of Char;

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: