Solved

Finding what an untyped pointer points to

Posted on 1997-08-13
7
227 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

Technology Partners: 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!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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