Solved

Finding what an untyped pointer points to

Posted on 1997-08-13
7
223 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

9 Experts available now in Live!

Get 1:1 Help Now