Hi All!
I'm using external objects (ActiveX). I create instance of their and hold reference in variables.When I save image then what going with this objects? After reload image this objects dont restore. How I can restore state of external ActiveX objects? May be these ActiveX must implements IPersist*** ? Any ideas are welcomed! I'm just considering about using SmallTalk in our products and we have many legacy ActiveX libs and controls, which I am going to continue to use. |
Pavel,
have a look at the DocumentShell, command category for methods such as #fileSave, fileSaveAs. Basically, you can offload your Smalltalk objects to disk and reload them the next time the application is run. Once you have reloaded your objects, you can send messages to your ActiveX components and set their values. Your collection of objects will be saved as Binary Objects via the STB format. A Dolphin Smalltalk Binary object format. STB files are created using the STB streaming mechanism (STBOutFiler, STBInFiler etc.) and are a means by which object instances can be exported from an image such that they can be transported and reloaded elsewhere. Using STB, objects can be easily streamed to files or to byte arrays. Here is some sample code... saveObjects: myObjects "Private - Save the receivers collection of objects to disk" | aFileStream objectFiler systemObjects pathFileName | pathFileName := self filePathName. aFileStream := FileStream write: pathFileName text: false. [ objectFiler := ( STBOutFiler on: aFileStream ). objectFiler nextPut: myObjects ] ensure: [ aFileStream flush; close ]. loadObjects "Load my objects from disk" | aFileStream aPersistentObjects objectFiler pathFileName | pathFileName := self defaultPathFileName. (File exists: pathFileName) ifTrue: [ aFileStream := FileStream read: pathFileName text: false. objectFiler := ( STBInFiler on: aFileStream ). "[ aFileStream atEnd ] whileFalse: [ anObject := objectFiler next ]." aPersistentObject := objectFiler next. aFileStream close. self initializeAfterLoad: aPersistentObjects. ] The initializeAfterLoad: is where you will extract your smalltalk objects and send messages to your ActiveX controls that should be in smalltalk memory as instances of IDispatch. Hope that helps, Pax |
In reply to this post by Pavel
Pavel wrote:
> I'm using external objects (ActiveX). I create instance of their and hold > reference in variables.When I save image then what going with this > objects? After reload image this objects dont restore. How I can restore > state of external ActiveX objects? May be these ActiveX must implements > IPersist*** ? Any ideas are welcomed! Have you looked at using AXControlSite-s ? I know very little about ActiveX, but as far as I can tell from reading the code, the AXControlSite view makes an effort to save/restore its ActiveX object when the image is saved/restored. It appears from AXControlSite>>binaryStoreControlOnIStream: that it attempts to ask the object for its IPersistStreamInit or, failing that, for its IPersistStream, and saves the resulting bytes as part of the image when Dolphin is shutdown. I don't know exactly what that means in ActiveX terms, but it looks promising... As an aside. Only a few kinds of objects in Dolphin "know" how to save/restore any external counterpart they may have as the image is shut-down/restarted. External memory, and external "objects" just vanish as Dolphin shuts down and are not restored as it starts up. There are a few special cases where a higher-level object "knows" how to re-create its external objects. For instance File and Socket instances attempt to re-open themselves as the image starts (personally, I don't think that's a good idea, although it can be handy). Above all, Views make huge efforts to do re-create themselves. The heart of the View implementation are the #state and #state: methods which save and restore the apparent state of the external object (in this case a Windows control or whatever) as the image is saved and restored. That involves rather a lot of code, since each View class has to save different information. And even so it's not quite perfect, there are some aspects of the states of, say, a TreeView that are not perfectly restored when Dolphin restarts. Anyway, AXControlSite>>state is where Dolphin invites the underlying ActiveX object to provide a persisted representation of itself. -- chris |
Free forum by Nabble | Edit this page |