Solved

Finding what an untyped pointer points to

Posted on 1997-08-13
7
224 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 174
TVirtualStringTree  search using TEdit 7 106
tidtcpserver connection lost handle 2 71
Multi-layered image in FireMonkey 9 17
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now