?
Solved

Finding what an untyped pointer points to

Posted on 1997-08-13
7
Medium Priority
?
229 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Accepted Solution

by:
icampbe1 earned 100 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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