Solved

Finding what an untyped pointer points to

Posted on 1997-08-13
7
228 Views
Last Modified: 2010-04-06
I am writing a series of 'classic' datastructures (LinkedList, Stack, Queue etc.) for delphi that I intend to post to DSP for all to use.

I am fisrtly attempting the linked list by inheriting TList and overiding the delete, Clear, and Destroy methods to free any list items that are taken from the list. I am overriding remove as a function which returns a pointer to the removed item.

It seemed a very simple task and it works fine so long as you only use the list to store decendants of TObject. (so that the .free can be used)

A also want to be able to store the basic types such as integer, boolean etc. In these cases there is no free method and typcasting the pointer to Tobject gives an access violation.

What I am trying to do is to find out if the pointer can be cast as a tobject then free it otherwise don't

I have tried casting the pointer as a variant and then getting the varType but it is giving inconsistent results.

Is this possible? I suspect that this may be why Tlist doesn't free up it's resources.

I have delphi 2.01


0
Comment
Question by:essbb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:peter_vc
ID: 1341280
Just to let you know I downloaded a library exactly like this from the DSP a couple of days ago.  It comes with source, so you may want to have a look at it.


0
 
LVL 1

Expert Comment

by:jturpin
ID: 1341281
What is DSP ?
0
 
LVL 1

Expert Comment

by:peter_vc
ID: 1341282
The DSP is short for The Delphi Super Page.  It is a web site (out of Poland I believe) dedicated to Delphi 1,2,3 and C++ Builder.  Check there first when looking for anything to do with Delphi.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
icampbe1 earned 50 total points
ID: 1341283
I'm assuming that you still want an answer to your question for knowledge reasons.  

Although you can cast the TList's pointer to a Longint (or any 32-bit type), you wont be able to tell it from an object pointer.  I would therefore recommend that you create a series of mini-objects to contain simple ordinal like values.  Then you can treat the management of the list in a consistent manner.

For example:

TInteger = CLASS( TObject )
PRIVATE
  FValue: Integer;
PUBLIC
  PROPERTY  IntValue: Integer  Read FValue Write FValue;
END;

This object, and others like it for boolean, double, real... can be added to the list.  You don't even need to write a constructor/destructor because they don't do any special processing on create.  Using these mini-objects lets you do stuff like:  IF (Something IS TInteger) THEN...

You might explire the possibility of on object type with several properties as well.

Cheers,
Ian C.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341284
do you try TVarRec type ? i think so no. Try this now.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341285
Sorry. You need VarData not VarRec but this can help you.
0
 

Author Comment

by:essbb
ID: 1341286
Thanks for the answer,
Thats pretty much what I thought
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question