Solved

Save/reload the app in his current state

Posted on 1998-10-22
6
275 Views
Last Modified: 2010-04-06
Hi,
I want a way to save on disk my app (with all edits/... controls filled ... when the user close the app.
Then when he run the app again, all is in the same state.
(like in Turbovision "save the desktop" ???)

Thanks,

Jean-Pol
0
Comment
Question by:jpdupont
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344035
Hi jdupont,

 use TFormStorage of the Freeware RxLib library!!!

http://torry.rimini.com/vcl/packs/rxlib.zip

Regards, Zif.
0
 

Author Comment

by:jpdupont
ID: 1344036
Thanks ZifNab,

I know RX (and use the lib intensivelly)
but RX form storage don't store all properties of all components : ex. ItemIndex is not stored. Don't store the memo text, ...

My app is a training app with 17 type of exercises : my form is created at run time (with all compenents). I read some tips about tFileStream.WriteComponent : Any way to do a "TFiletream.WriteForm(MyForm1)" and reload then with a readform(MyForm1) ?

Jean-Pol
0
 
LVL 3

Expert Comment

by:Stefaan
ID: 1344037
Hi Jean-Pol,

Maybe you could store all those values (form size, form position, other properties) in the registry ?  Use the TRegistry class to create, read and save values to the registry.  Create a key for your application and keys for the components, then for each component property, create a value in the Component key of the registry.  When you restart the Application, you can read the Registry to see if there are values available, and use them to re-create the forms as they were the last time.

Creating a Key can be done using :

TRegistry.CreateKey('NameOfTheKeyToCreate');

Opening a Key :

TRegistry.OpenKey('NameOfTheKeyToOpen');

Reading the values from withing a key can be done with the ReadInteger, ReadString, ReadBool, ... methods and writing values using the WriteInteger, WriteString, WriteBool methods :

TRegistry.WriteString('Nameofthevalue','StringToWrite');
TRegistry.ReadString('NameOfTheValueToRead');

This way you can create a root key for your application, several sub keys for each form, with subkeys for the components and values for the properties (look in the Help files for more info on the TRegistry class).  

I hope that this will be of any help to you.

Greetings and best regards,


Stefaan Lesage.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jpdupont
ID: 1344038
Hi Stefaan,

Thanks for the answer.
I know registry - and registry use ;) -.
(I don't like to fill the registry with many data (memo / stringlist ...) I always chose inifiles. Easy to debug.)

When the user close the app, I don't know what is on the screen : (the exercises screens are drawned by a exercise script (18 different exercises scripts) with data structures filled by the user (some text typed by the user, user wav recording, user actions, user validations, ...) I want to take a snapshot of all this before the user close the app. Then , when he reload the app, he work instantly in the same "application state" he worked before he closed the app.

I want to automatically loop around the app/forms/data on the screen/... and save all this in a userfile (maybee many users on the same PC -> in a school). Then I want to read the userfile to reload all the screen/app parts, in the reverse order.

Regards,

Jean-Pol
0
 

Expert Comment

by:john_m
ID: 1344039
If you want only visual components saving their state then you may like to look at the ReadComponent and WriteComponent methods of TxxxStream.

If you are wanting to save unpublished properties of both non-visual and visual components then I would advise you to look at the Spider classes. They can be found at the DSP.

If you want any more information after reading up on these two areas, then get in touch.

John_M
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1344040
What you want to do is derive a class from TForm that overrides the Loaded and Close(?) methods (ie: immediately after the form is loaded from disk, and immediately before it is closed.

You then derive all your forms from this one (just change the class(TForm) to class(TMyForm)).

The method that is fired by closing the form iterates through all the components and for each writes out its component name (or index), and the necessary information

eg:
  with TIniFile.Create('MyIniFile') do
    for I := 0 to ComponentCount - 1 do
        if components[i] is TEdit then
          WriteString(Caption, 'Component'+inttostr(i), (Components[i] as TEdit).text)
       else
          if components[i] is TComboBox then
    // you get the picture

In the overriden loaded method of TMyForm reverse the procedure reading in the values for each of the components...

This should workj fairly well for what you want to do (especially if there are a limited number of types of components and the actual informaiton that needs to be stored is modest.

Cheers,

Raymond.        
 
       
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month5 days, 9 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question