Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Understanding some basics...Lists


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Mar 6, 2017 12:27 PM Last Post By: Paul Jackson
Paul Jackson

Posts: 61
Registered: 3/2/17
Understanding some basics...Lists  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 5, 2017 10:16 AM
Having a hard time understanding some of the basics. I need to keep a simple list of objects of customers. I was thinking of using an TObjectList.

What are the differences between using TList, TStringList, TObjectList and the std::collections library stuff? Is one way preferred over the other?

My program has a VCL UI. I have a simple class defined to keep information about customers. The members of the class will be displayed in the UI, i.e. first name, last name, all the normal stuff. In the class there will also be a list of activities each customer does.

Basically I'm tracking 2 lists. One is the main list of customers and the other is an embedded list in each customer. I'm looking for the best approach for keeping these lists.

Thank you for any discussion.

-Paul
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: Understanding some basics...Lists
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 5, 2017 2:45 PM   in response to: Paul Jackson in response to: Paul Jackson
Hi Paul

There are a lot of videos here: https://www.youtube.com/user/vclexamples/videos
to help you get a grip on the basics VCL.

And this guy have made a lot of videos on C++
https://www.youtube.com/channel/UCEOGtxYTB6vo6MQ-WQ9W_nQ

Best regards
Asger

Paul Jackson

Posts: 61
Registered: 3/2/17
Re: Understanding some basics...Lists  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 5, 2017 4:08 PM   in response to: Asger Joergensen in response to: Asger Joergensen
Thank you Asger, I will definitely check these out.

Asger Joergensen wrote:
Hi Paul

There are a lot of videos here: https://www.youtube.com/user/vclexamples/videos
to help you get a grip on the basics VCL.

And this guy have made a lot of videos on C++
https://www.youtube.com/channel/UCEOGtxYTB6vo6MQ-WQ9W_nQ

Best regards
Asger

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Understanding some basics...Lists  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 11:25 AM   in response to: Paul Jackson in response to: Paul Jackson
Paul wrote:

Having a hard time understanding some of the basics.

Why? What is so hard to understand about them?

I need to keep a simple list of objects of customers. I was thinking of
using an TObjectList.

That will only work for classes that are derived from the Delphi TObject
class. And as such, it also requires the objects to be allocated on the
heap only. Pure C++ does not have that restriction.

What are the differences between using TList, TStringList, TObjectList
and the std::collections library stuff? Is one way preferred over
the other?

If you are writing pure C++ code, stick with the C++ STL containers.

TList, TStringList, TObjectList, these are all Delphi-based classes. You
should prefer these classses only when interacting with the Delphi-based
RTL/VCL/FMX frameworks.

TList is just a dynamic list of raw pointers. The C++ STL equivilent would
be std::vector<void*> container.

TStringList is just a dynamic list of System::String values and associated
TObject* pointers, with a few methods added for handling "name=value" strings.
The C++ STL equivilent would be a std::vector<std::pair<String, TObject*>>
or a std::map<String, std::pair<String, TObject*>> container.

TObjectList is just a dynamic list of TObject* pointers with optional ownership
semantics. The C++ STL equivilent would be a std::vector<TObject*> (no ownership)
or std::vector<std::unique_ptr<TObject>> (ownership) container.

My program has a VCL UI. I have a simple class defined to keep
information about customers. The members of the class will be
displayed in the UI, i.e. first name, last name, all the normal stuff.

That does not require using Delphi-based containers. you certainly can if
you want to, but then your code will not be portable should you ever need
to use other compilers.

In the class there will also be a list of activities each customer
does.

Easily implemented using either Delphi-based or STL-based lists.

Basically I'm tracking 2 lists. One is the main list of customers and
the other is an embedded list in each customer. I'm looking for the
best approach for keeping these lists.

"Best" is a matter of opinion, as there are many different ways to approach
this from a coding perspective.

--
Remy Lebeau (TeamB)
Paul Jackson

Posts: 61
Registered: 3/2/17
Re: Understanding some basics...Lists  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 12:26 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Perfect, exactly the feedback I needed. Thank you very much Remy. And again to you Asger.

Remy Lebeau (TeamB) wrote:
Paul wrote:

Having a hard time understanding some of the basics.

Why? What is so hard to understand about them?

I need to keep a simple list of objects of customers. I was thinking of
using an TObjectList.

That will only work for classes that are derived from the Delphi TObject
class. And as such, it also requires the objects to be allocated on the
heap only. Pure C++ does not have that restriction.

What are the differences between using TList, TStringList, TObjectList
and the std::collections library stuff? Is one way preferred over
the other?

If you are writing pure C++ code, stick with the C++ STL containers.

TList, TStringList, TObjectList, these are all Delphi-based classes. You
should prefer these classses only when interacting with the Delphi-based
RTL/VCL/FMX frameworks.

TList is just a dynamic list of raw pointers. The C++ STL equivilent would
be std::vector<void*> container.

TStringList is just a dynamic list of System::String values and associated
TObject* pointers, with a few methods added for handling "name=value" strings.
The C++ STL equivilent would be a std::vector<std::pair<String, TObject*>>
or a std::map<String, std::pair<String, TObject*>> container.

TObjectList is just a dynamic list of TObject* pointers with optional ownership
semantics. The C++ STL equivilent would be a std::vector<TObject*> (no ownership)
or std::vector<std::unique_ptr<TObject>> (ownership) container.

My program has a VCL UI. I have a simple class defined to keep
information about customers. The members of the class will be
displayed in the UI, i.e. first name, last name, all the normal stuff.

That does not require using Delphi-based containers. you certainly can if
you want to, but then your code will not be portable should you ever need
to use other compilers.

In the class there will also be a list of activities each customer
does.

Easily implemented using either Delphi-based or STL-based lists.

Basically I'm tracking 2 lists. One is the main list of customers and
the other is an embedded list in each customer. I'm looking for the
best approach for keeping these lists.

"Best" is a matter of opinion, as there are many different ways to approach
this from a coding perspective.

--
Remy Lebeau (TeamB)

Edited by: Paul Jackson on Mar 6, 2017 12:26 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02