# 'Key' property of Shape object not work

**URL:** https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250
**Category:** MapWinGIS
**Created:** [February 17, 2022, 12:16pm UTC](https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250 "2022-02-17T12:16:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://mapwindow.discourse.group/u/josimar)
#### Post date: [February 17, 2022, 12:16pm UTC](https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250/1 "2022-02-17T12:16:45Z")

</div>

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:

```auto
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:

```auto
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;

```

---

<div class="post-metadata">

### Author: ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)
#### Post date: [February 17, 2022, 9:29pm UTC](https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250/2 "2022-02-17T21:29:51Z")

</div>

Hello @josimar

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?

Regards,  
Jerry.

---

<div class="post-metadata">

### Author: ![josimar.alves](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@josimar.alves](https://mapwindow.discourse.group/u/josimar.alves)
#### Post date: [February 18, 2022, 10:59am UTC](https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250/3 "2022-02-18T10:59:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![josimar.alves](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@josimar.alves](https://mapwindow.discourse.group/u/josimar.alves)
#### Post date: [February 20, 2022, 2:16am UTC](https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250/4 "2022-02-20T02:16:10Z")

</div>

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';`

So could you check if this make sence ?

---

<div class="post-metadata">

### Author: ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)
#### Post date: [February 20, 2022, 6:36pm UTC](https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250/5 "2022-02-20T18:36:25Z")

</div>

Hello @josimar.alves

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?

Regards,  
Jerry.

---

<div class="post-metadata">

### Author: ![josimar.alves](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@josimar.alves](https://mapwindow.discourse.group/u/josimar.alves)
#### Post date: [February 20, 2022, 10:10pm UTC](https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250/6 "2022-02-20T22:10:42Z")

</div>

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.
