Solved

Save/reload the app in his current state

Posted on 1998-10-22
6
265 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
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now