Re: Add integer to a TList

From: Wayne Niddery [TeamB] (wniddery_at_chaff.aci.on.ca)
Date: 10/23/03


Date: Thu, 23 Oct 2003 10:20:40 -0400

Alan wrote:
> What I don't understand is there are two 7's.
>
> The '7' in the TList is somewhere in the memory, and another '7' is
> somewhere else. So the addresses of both '7' are different, although
> the integer value is the same 7, how the TList is able to return the
> index ?
>>
>> index := MyList.IndexOf(pointer(7));

No, there is only one 7, the one being passed in this example. It is not
being stored elsewhere in memory, and then being pointed to by the TList,
the cast to pointer is telling the compiler to accept 7 *as though it were a
pointer* and store that directly in the TList. E.g.:

MyList.Add(pointer(7)); // store 7 in the TList
index := MyList.IndexOf(pointer(7)); // find that 7

Of course you can also do this:

var i: integer;
begin
    i := 99;
    MyList.Add(pointer(i)); // store 99 in the TList
    index := MyList.IndexOf(pointer(i)); // find that 99

-- 
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"It is error alone which needs the support of government. Truth can
stand by itself." - Thomas Jefferson


Relevant Pages

  • Re: the adress register, is good choice ?
    ... A store, store T into A ... a@ A fetch, fetch T from A ... store from T into memory using A as a pointer ... when using the top of the return stack as a memory pointer. ...
    (comp.lang.forth)
  • Re: void *
    ... A container that can store any kind of object, ... If you want to *store* objects in the linked list, as you say, then ... One of the code snippets Roman ... would result in a pointer to somewhere where the number 100 ...
    (comp.lang.c)
  • Re: What is a sequence point?
    ... and the store to a only depends on the value stored in b being calculated ... If they all have the same types, any self-respecting optimizing compiler ... will load the value once and store it twice without doing anything else ... load a1,a;Load location to store word pointer ...
    (comp.lang.c)
  • Re: GetOpenFileName filters not working
    ... store a pointer with each window and store all of the unique data you want. ... HWND hWnd; ...
    (microsoft.public.win32.programmer.ui)
  • Re: set!, mutation or rebinding?
    ... an memory adresses, where the "contents" of the value is stored. ... pointer, and then go on from there to store other "small" types ... tag of 1 and so on -- and store or fetch values with shift and mask ... So it works in code that the system sees {integer tag} ...
    (comp.lang.scheme)