[fpc-pascal] Heterogenous list of objects
Hi, I'd like to manage a list of heterogenous objects. For instance, I have a list of objects to buy in store: cheeses (of class TCheese), soaps (of class TSoap), flowers (of class TFlower), etc... I thought to gather pointers to different objects of these classes in a TList. But, when it comes to manipulate or destroy these items, I am in trouble: I have lost the information about the precise type of the object the pointer points to. Does somebody have an idea? Thanks in advance, Gilles Marcou ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: Re: [fpc-pascal] Heterogenous list of objects
Hi all, thanks for your kind and fast answer. Effectively, TObjectList is what I need. Thanks to Damien, I understand a bit better how it works. But in my case I believe that I need to use some kind of TList of TObjectList. So is it possible to build a class that will have TObjecList member so that I will be able to use TList of this class? For instance: - TToDo=class(TList) private fProducts: TObjectList;//Cheeses, Soaps, etc. fShops: TObjectList;//Shops, Markets, Internet,... public property Products: TObjectList read fProducts write fProducts; property fShops: TObjectList read fShops write fShops; creator Create; destructor Destroy; override; procedure Clear; override; ... end; - I may have to say more about my project so you'll have better insight in my design problem. I have an XML to drive my application to do a set of diverse actions. Root | |-action1-|-action11 | |-action12 | |-action2-|-action21 |-action22 action1 and action2 shall be a TObjectList because action11, action12,... can be instances of different classes. Then I want action1 and action2 to be stored in some kind of container (I believe a TList). So I call to your opinion to see if it is an acceptable design and if I am not mixing incompatible concepts (TList and TObjectList). Thanks for your insight, Gilles Marcou ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] XML Programming..
Hi, I used some tutorial: http://wiki.lazarus.freepascal.org/Networking http://www.thomas-zastrow.de/texte/fpcxml/dom-reading.php The XML support is done using the FCL's units DOM, XMLRead, XMLWrite. I recommand you to take a look in Lazde. This is the documentation editor of Lazarus. It is based on XML so it does use XML units. So I believe it is a good example even if the software is yet a little bit unstable. Ciao, Gilles Marcou -- Message: 10 Date: Mon, 11 Feb 2008 08:15:23 +0700 From: <[EMAIL PROTECTED]> Subject: [fpc-pascal] XML Programming.. To: Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii" Hi.. I'm looking for an example how to use or programming XML in fpc.. n the documentation I hope.. Tq.. Regards, EAM ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Basic question about TStringList
Hi, I seek help to clarify a very basic use of TStringList. Let A and B be TStringLists. What is the difference between: A:=B; and A.Assign(B); ? Thanks in advance for your help, Gilles Marcou ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Basic question about TStringList
Hi, thanks for your very clear answer. In fact this is chilling me as I am thinking to the huge amount of memory leaks that I certainly have in my developements... This means that whenever the assignement operator ":=" is used with TStringLists, the recieving list shall never be created! As a consequence I have another question. Suppose I have a function that returns a TStringList: Myfunction(): TStringList; I must have inside a line like: Result:=TStringList.Create; Let A be a TStringList, I have two ways to catch the result of my function: A:=Myfunction(); or A.Assign(Myfunction()); In the first case, if do A.Free, I release the memory allocated by the function. What's arriving in the second case? I can do A.Free, but does that action will also release the memory allocated by the function? By the way, do you have some tricks to detect this kind of error? Thanks again, Gilles Marcou ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal