Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-12

Fwd: Need help in streaming components

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Kiên Nguyễn Tiến Trung

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.

I want Class1.txt should be like this:

object TClass1
Value1 = 0
object TClass2
Value2 = 0
end

I really appreciate any help you can provide.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141214/8e766ddc/attachment.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: cs2.zip
Type: application/zip
Size: 2356 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141214/8e766ddc/attachment.zip>

Reply by email

Howard Page-Clark
to Kiên Nguyễn Tiến Trung
Ki?n Nguy?n Ti?n Trung wrote 6 lines
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unit1.zip
Type: application/zip
Size: 789 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141214/1152e276/attachment.zip>

Reply by email

Kiên Nguyễn Tiến Trung
to Howard Page-Clark

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 :

Show quoted text 39 lines
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 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141215/a57a406d/attachment.html>

Reply by email

Glaucos Ginez
to Kiên Nguyễn Tiến Trung

Try TObjectList.

2014-12-15 1:02 GMT-03:00 Ki?n Nguy?n Ti?n Trung :

Show quoted text 58 lines
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 > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141215/387eafc9/attachment-0001.html>

Reply by email

Martin Frb
to Kiên Nguyễn Tiến Trung: Thank you for your respond. I find that my real problem is more complex and need more…
Ki?n Nguy?n Ti?n Trung wrote 5 lines
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.

Reply by email

Mattias Gaertner
to Glaucos Ginez: Try TObjectList. 2014-12-15 1:02 GMT-03:00 Ki?n Nguy?n Ti?n Trung : -------------- next…
Try TObjectList.

That does not support streaming.

Show quoted text 7 lines
[...] > 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

Reply by email

Kiên Nguyễn Tiến Trung
to Mattias Gaertner

I got it!

Thank all of you very much.

2014-12-15 17:49 GMT+07:00 Mattias Gaertner :

Show quoted text 39 lines
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 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141215/c2630f0c/attachment.html>

Reply by email