Hi everyone, I’m facing problems using the “Key” property.
In my project I need to set a value of the “Key” property of Shape and Shapefile objects.
After I set Key value of a Shapefile object I sucessfully can get the Key value in other function of my code .
But, if I set Key value of a Shape object when I try to get the Key value in other function the value was not correct. I think the Key property of Shape object was not implemented in the Mapwindow code or it’s read only. Can anyone help me to find a solution?
My code in pascal is like this:
procedure SetMyKeyValue;
begin
FWPS:= CoShapefile.Create ; //FWPS is a global variable
FWPS.CreateNewWithShapeID ('',SHP_POINT);
IdLayer := FWMap.AddLayer (FWPS, True); //IdLayer is a global variable
if IdLayer<0 then begin
raise Exception.Create( 'Create Error');
exit;
end;
FWPS.Key := IdLayer.ToString; //set Key for Shapefile
sh := CoShape.Create;
sh.Create (SHP_POINT); // SHP_POINT
sh.AddPoint (lng, lat); // lat,lng was set before
sh.Key := FWPS.NumShapes.ToString; //store Key value
idShape := FWPS.EditAddShape(sh); //idShape is a global variable
end;
This the my code to get Key value:
procedure GetMyKeyValue;
var sKey: string;
begin
//The Key returned here is not the correect value stored
sKey := FWPS.Shapegile[IdLayer].Shape[IdShape].Key; //sKey returned
end;
I checked the source code and it looks like it is properly implemented; I would have to try to reproduce the problem in a test app.
It looks from your code that the Key stored would be a zero, since you had not yet added the shape to the shapefile, NumShapes would equal zero. What value did you get back?
Hi @jerryfaust thanks for you atention.
In my test any value stored is not saved in the property key. Only works in shapefile object.
I solve my problem storing my variable in other place outside of shape object. For now it’s solved, but I will see if the problem is in my TLB file because I’m using Delphi language.
Hi @jerryfaust after I checked my TLB file created from Delphi and I think the problem is because of this line of code of Shape property in Shapefile object, as you can see below: property Shape[ShapeIndex: Integer]: IShape read Get_Shape;
As you can see this is read only property (i.e. there is no “Set_Shape” procedure) when it usualy have to be in this mode (but there is no “Set_Shape” procedure in TLB file): property Shape[ShapeIndex: Integer]: IShape read Get_Shape write Set_Shape;
For example, I also verifyed that Key property of the Shapefile object and this seens correct as you can see below (once the Key property is saved correctly): property Key: WideString read Get_Key write Set_Key;
So, in my code (see below) when I set the shape object this no change the Shape object, once this is a read only property: Map1.Shapefile [idLayer].Shape[IdShape].Key := 'Shape2 Key';
I rechecked the definition, and it is defined as both read and write. It’s possible that some of the methods were lost in translation. I have even seen this in Microsoft’s own tools, when importing the TLB for a c++ projection, it lost some of the methods. However, when importing the TLB, it created an editable file that was compiled into the new program, and I was able to edit the file to add functions that I knew existed, and it was able to find them at runtime.
Are you able to edit the imported file to add functions?
Thank you @jerryfaust for help me with this issue.
I’ll try to add a new function on TLB file to set the property to write the value as you mentioned. I’ll let you know.