Sign in Join

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

Mailing lists / fpc-pascal / 2018-02

Is there a smart way to save/restore NotifyEvents and objects?

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Dennis

I have list of objects which contains references to other objects. I need to save all these objects to harddisk to be restored on a latter day.

I know how to stream the data fields of these objects to a TFileStream but the tricky part is these how to restore the object references.

The only way I can think of is to assign unique IDs to each objects and store these IDs to file.
When these objects are later restored, I used these IDs find the actual objects and re-assign them back to the object references.

It is tedious. Is there a smarter way?

Also, there are some TNotifyEvent fields e.g. OnClick, OnClose etc. How do I save and restore them from file?

Many thanks in advance.

Dennis

Reply by email

Sven Barth

Am 02.02.2018 17:53 schrieb "Dennis" :

I have list of objects which contains references to other objects. I need to save all these objects to harddisk to be restored on a latter day.

I know how to stream the data fields of these objects to a TFileStream but the tricky part is these how to restore the object references.

The only way I can think of is to assign unique IDs to each objects and store these IDs to file.
When these objects are later restored, I used these IDs find the actual objects and re-assign them back to the object references.

It is tedious. Is there a smarter way?

Also, there are some TNotifyEvent fields e.g. OnClick, OnClose etc. How do I save and restore them from file?

Many thanks in advance.

If your objects inherit from TComponent and you use published properties you can use the streaming screen of the RTL.

Regards,
Sven

Reply by email

Dennis Poon
to Sven Barth
Sven Barth wrote 27 lines
Am 02.02.2018 17:53 schrieb "Dennis" < >: I have list of objects which contains references to other objects. I need to save all these objects to harddisk to be restored on a latter day. I know how to stream the data fields of these objects to a TFileStream but the tricky part is these how to restore the object references. The only way I can think of is to assign unique IDs to each objects and store these IDs to file. When these objects are later restored, I used these IDs find the actual objects and re-assign them back to the object references. It is tedious. Is there a smarter way? Also, there are some TNotifyEvent fields e.g. OnClick, OnClose etc. How do I save and restore them from file? Many thanks in advance. If your objects inherit from TComponent and you use published properties you can use the streaming screen of the RTL.

I am curious how TComponent save and restore TnotifyEvent fields. Can you explain a little bit?
Also, what is 'streaming screen' of RTL? How to use it?

Thanks.

Dennis

Reply by email

Michael Van Canneyt
to Dennis Poon
Dennis Poon wrote 7 lines
> > > If your objects inherit from TComponent and you use published > properties you can use the streaming screen of the RTL. > I am curious how TComponent save and restore TnotifyEvent fields. Can you explain a little bit?

Roughly:

If you put a method in the published section of an object, its name is written to RTTI. It can be retrieved and set using the RTTi based on the name: when saving, the name is written to stream, when loading, the name is looked up in RTTI.

The classes TReader and TWriter in the classes unit perform this work.

Also, what is 'streaming screen' of RTL? How to use it?

He meant the streaming system, I suppose. TComponent, TReader and TWriter together form the streaming system.

Michel.

Reply by email

Sven Barth
to Michael Van Canneyt

Am 03.02.2018 09:11 schrieb "Michael Van Canneyt" :

Dennis Poon wrote 7 lines
> > If your objects inherit from TComponent and you use published properties > you can use the streaming screen of the RTL. > > I am curious how TComponent save and restore TnotifyEvent fields. Can you explain a little bit?

Roughly:

If you put a method in the published section of an object, its name is written to RTTI. It can be retrieved and set using the RTTi based on the name: when saving, the name is written to stream, when loading, the name is looked up in RTTI.

The classes TReader and TWriter in the classes unit perform this work.

Of course this only works for methods that are published.

Also, what is 'streaming screen' of RTL? How to use it?

He meant the streaming system, I suppose. TComponent, TReader and TWriter together form the streaming system.

Correct. Stupid autocorrection -.-

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 26 lines
Am 03.02.2018 09:11 schrieb "Michael Van Canneyt" : On Sat, 3 Feb 2018, Dennis Poon wrote: >> >> If your objects inherit from TComponent and you use published properties >> you can use the streaming screen of the RTL. >> >> I am curious how TComponent save and restore TnotifyEvent fields. Can you > explain a little bit? > Roughly: If you put a method in the published section of an object, its name is written to RTTI. It can be retrieved and set using the RTTi based on the name: when saving, the name is written to stream, when loading, the name is looked up in RTTI. The classes TReader and TWriter in the classes unit perform this work. Of course this only works for methods that are published.

Absolutely, that is why it was the first sentence of my reply :)

Show quoted text 8 lines
Also, what is 'streaming screen' of RTL? How to use it? > He meant the streaming system, I suppose. TComponent, TReader and TWriter together form the streaming system. Correct. Stupid autocorrection -.-

Don't you hate it when computers think they're smarter than you ? ;-)

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt

Am 03.02.2018 10:08 schrieb "Michael Van Canneyt" :

On Sat, 3 Feb 2018, Sven Barth via fpc-pascal wrote:

"Michael Van Canneyt" wrote 27 lines
On Sat, 3 Feb 2018, Dennis Poon wrote: >> If your objects inherit from TComponent and you use published properties >> you can use the streaming screen of the RTL. >> >> I am curious how TComponent save and restore TnotifyEvent fields. Can you >> > explain a little bit? > > Roughly: If you put a method in the published section of an object, its name is written to RTTI. It can be retrieved and set using the RTTi based on the name: when saving, the name is written to stream, when loading, the name is looked up in RTTI. The classes TReader and TWriter in the classes unit perform this work. Of course this only works for methods that are published.

Absolutely, that is why it was the first sentence of my reply :)

Ah right, sorry. It was still before breakfast when I answered that. ^^'

Also, what is 'streaming screen' of RTL? How to use it?

Show quoted text 9 lines
> > He meant the streaming system, I suppose. TComponent, TReader and TWriter together form the streaming system. Correct. Stupid autocorrection -.-

Don't you hate it when computers think they're smarter than you ? ;-)

Definitely :P

Regards,
Sven

Reply by email