Re:URGENT : Your help on Delphi's Queues and Lists needed
Quote
Behrooz wrote:
>I am trying to convert an existing simulation application which has been
>written in MODSIM (an object oriented Simulation Language) to Delphi.
>Can anyone tell me how I can set up a Queue of Objects (or a list of
>objects) in Delphi.
>These objects are things like Cars e.g. have a methods and attributes
>....and I want to have the ability of doing things like;
>FOREACH DummyObject in Queue1
> Print DummyObject.name
> Print DummyObject.speed
>END FOREACH
>so that way I go through the whole list and print the names and speeds of
>every single car (there could be as much as 10000 cars in the Queue)
>Also, is it possible to have a Queue of Queues or a List of Lists
The object you want is either a TStringLIst or a TList. TStringLIst allows you
to store an object along with each string. That object can be anything that
inherits from TObject, which is every object in Delphi. TList lets you do that
as well, but with TStringList you can have some easily searchable label
associated with each object.
If you had a TStringList of your TCar objects, your code above would look like
this:
for i := 0 to (carList.Count - 1) do
begin
MyPrintFunction((carList.Objects[i] as TCar).name) ;
MyPrintFunction((carList.Objects[i] as TCar).speed) ;
end ; // for i := 0 to (carList.Count - 1)
--
Clayton Neff
Software Project Leader
The Personal Marketing Company, Inc.
11843 West 83rd Terrace
Lenexa, KS 66214
(913)492-0322
clay...@tpmco.com