Re: [Lazarus] Fwd: Need help in streaming components

2014-12-14 Thread Kiên Nguyễn Tiến Trung
Thank you for your respond. I find that my real problem is more complex and
need more help from you.

I want my TClass1 can contain many TClass2. It means that number of TClass2
in TClass1 is not fixed.

I've tried to use TComponentList, but it does not work. I knew that
TCollection supports streaming, however, TClass1 and TClass2 must be
TComponent.

2014-12-15 0:23 GMT+07:00 Howard Page-Clark :
>
> On 14/12/2014 12:23, Kiên Nguyễn Tiến Trung wrote:
>
>>
>> I am trying to streaming. I spent a lot of time but I didn't find the
>> proper solution.
>>
>> I have two classes, TClass1, TClass2. Although the parent of AClass2 is
>> AClass1, AClass2 isn't saved into specified file, only AClass1 is.
>>
>
> AClass1 is not the parent of AClass2. The two classes have no
> relationship, certainly not a hierarchical relationship.
>
> You make AClass1 the *owner* (not the *ancestor*) of AClass2 for that
> single instantiation in your program (i.e. responsible for correctly
> freeing the instance).
>
> However, TClass1 and TClass2 are completely unrelated, and know nothing
> about each other's properties.
> Perhaps you are looking for something like the attached zipped unit1.pas.
>
> Howard
>
>
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> http://www.avast.com
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Fwd: Need help in streaming components

2014-12-15 Thread Glaucos Ginez
Try TObjectList.

2014-12-15 1:02 GMT-03:00 Kiên Nguyễn Tiến Trung :
>
> Thank you for your respond. I find that my real problem is more complex
> and need more help from you.
>
> I want my TClass1 can contain many TClass2. It means that number of
> TClass2 in TClass1 is not fixed.
>
> I've tried to use TComponentList, but it does not work. I knew that
> TCollection supports streaming, however, TClass1 and TClass2 must be
> TComponent.
>
> 2014-12-15 0:23 GMT+07:00 Howard Page-Clark :
>
>> On 14/12/2014 12:23, Kiên Nguyễn Tiến Trung wrote:
>>
>>>
>>> I am trying to streaming. I spent a lot of time but I didn't find the
>>> proper solution.
>>>
>>> I have two classes, TClass1, TClass2. Although the parent of AClass2 is
>>> AClass1, AClass2 isn't saved into specified file, only AClass1 is.
>>>
>>
>> AClass1 is not the parent of AClass2. The two classes have no
>> relationship, certainly not a hierarchical relationship.
>>
>> You make AClass1 the *owner* (not the *ancestor*) of AClass2 for that
>> single instantiation in your program (i.e. responsible for correctly
>> freeing the instance).
>>
>> However, TClass1 and TClass2 are completely unrelated, and know nothing
>> about each other's properties.
>> Perhaps you are looking for something like the attached zipped unit1.pas.
>>
>> Howard
>>
>>
>>
>>
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> http://www.avast.com
>>
>> --
>> ___
>> Lazarus mailing list
>> Lazarus@lists.lazarus.freepascal.org
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>>
>>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Fwd: Need help in streaming components

2014-12-15 Thread Martin Frb

On 15/12/2014 04:02, Kiên Nguyễn Tiến Trung wrote:
Thank you for your respond. I find that my real problem is more 
complex and need more help from you.


I want my TClass1 can contain many TClass2. It means that number of 
TClass2 in TClass1 is not fixed.


You may have to add
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
to TClass1

procedure TClass1.GetChildren(Proc: TGetChildProc; Root: TComponent);
begin
for i = 0 to ListOfClass2.count-1 do
Proc(ListOfClass2[i]);
end;

When loaded you need to put them back into that list. You con override 
TClass2.Loaded. The Owner of each Class2 will be the Class1 that saved it.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Fwd: Need help in streaming components

2014-12-15 Thread Mattias Gaertner
On Mon, 15 Dec 2014 07:34:12 -0300
Glaucos Ginez  wrote:

> Try TObjectList.

That does not support streaming.

 
>[...]
> > I want my TClass1 can contain many TClass2. It means that number of
> > TClass2 in TClass1 is not fixed.
> >
> > I've tried to use TComponentList, but it does not work. I knew that
> > TCollection supports streaming, however, TClass1 and TClass2 must be
> > TComponent.

The trick is overriding some TComponent methods.

TClass1
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
TClass2
procedure SetParentComponent(Value: TComponent); override;
function GetParentComponent: TComponent; override;
function HasParent: Boolean; override;

See for example
lazarus/examples/designnonlcl/mywidgetset.pas
class TMyWidget


Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Fwd: Need help in streaming components

2014-12-15 Thread Kiên Nguyễn Tiến Trung
I got it!

Thank all of you very much.

2014-12-15 17:49 GMT+07:00 Mattias Gaertner :
>
> On Mon, 15 Dec 2014 07:34:12 -0300
> Glaucos Ginez  wrote:
>
> > Try TObjectList.
>
> That does not support streaming.
>
>
> >[...]
> > > I want my TClass1 can contain many TClass2. It means that number of
> > > TClass2 in TClass1 is not fixed.
> > >
> > > I've tried to use TComponentList, but it does not work. I knew that
> > > TCollection supports streaming, however, TClass1 and TClass2 must be
> > > TComponent.
>
> The trick is overriding some TComponent methods.
>
> TClass1
> procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
> TClass2
> procedure SetParentComponent(Value: TComponent); override;
> function GetParentComponent: TComponent; override;
> function HasParent: Boolean; override;
>
> See for example
> lazarus/examples/designnonlcl/mywidgetset.pas
> class TMyWidget
>
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus