Jump to content
alogrep

Stringgrid objects problem

Recommended Posts

HI.

I have some stringgrids that use objects.

For most of them  the object is simply an integer (MySg.objects[c,r]:=Tobject(mynumber);;

A few use complext object that I declare and assign a Create/destroy consctructor/desctuctor.

Now when i try to delete an object of the "comples type" all works fine: the destructor takes care of it..

If i do 

if assigned(MySg.objects[c,r]) then
  MySg.objects[c,r].free

On the Integer type, I get an AV exception.

Perhaps the integer type object does not need to be freed.

But then how do I inpect if the object is of integer type or not?

MySG.objects[c,r].classname gives me a "not acessible" message.

Any helop, please?

 

Share this post


Link to post

What you are doing is very error prone, for the reasons you describe. If you are using low valued integers, you could inspect the value of the objects[x,y] and if the value is below some threshold, then do not free it.

 

One way of doing this is 

1. Make sure to set all objects[x,y] to zero

2. if setting it to an integer value, set it to the negative of the integer you want. Make sure to when using the value to negate it again

3. If setting to an object, store the pointer as a positive integer

 

then, when freeing, only free where objects[x,y] is a positive value.  I think that will work for 32 and 64 bit until you have set your 32 bit app to specifically use memory above 2GB block. 

 

 

Share this post


Link to post
5 hours ago, alogrep said:

Perhaps the integer type object does not need to be freed.

Correct.

5 hours ago, alogrep said:

But then how do I inpect if the object is of integer type or not?

You can't. So, either store all objects only, or all integers only. Don't mix types. But, if you must, then you'll need to either wrap the integers inside of objects, or add an extra header in front of each value to identify its type, etc.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×