Re: Add integer to a TList
From: Wayne Niddery [TeamB] (wniddery_at_chaff.aci.on.ca)
Date: 10/23/03
- Next message: Jeremy Collins: "Re: trouble with copies"
- Previous message: Wayne Niddery [TeamB]: "Re: Just out of curiosity"
- In reply to: Alan: "Re: Add integer to a TList"
- Next in thread: Alan: "Re: Add integer to a TList"
- Reply: Alan: "Re: Add integer to a TList"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jeremy Collins: "Re: trouble with copies"
- Previous message: Wayne Niddery [TeamB]: "Re: Just out of curiosity"
- In reply to: Alan: "Re: Add integer to a TList"
- Next in thread: Alan: "Re: Add integer to a TList"
- Reply: Alan: "Re: Add integer to a TList"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|