1

I have a form called fmTest. I use JVCL TJvFormStorage to store the the form placement, form size and form position in INI file if the program was terminated.

However, if I try to drag the windows control at run-time into the bottom until it just looks the header part only near the taskbar, then I release it and terminate the program, the fmTest is not start at that position when the program is started again.

I've been suggested to use the StoredProps and StoredValues methods in TJvFormStorage but I don't really understand how to use that methods.

Why TJvFormStorage not store the form position correctly? Is there any way to store the form position correctly using TJvFormStorage?

Thanks in advance.

Jessie M
  • 498
  • 1
  • 9
  • 23
  • what is saved in INI file actually, when the form is closed ? PS: JVCL official forum is at http://newsportal.delphi-jedi.org/index.php – Arioch 'The Mar 18 '13 at 10:11
  • @Arioch'The Yeah.. I've been try the `TFormStorage` from `RxLib` to store the forms values and it work correctly. However, I need to move into `JVCL` so I try to use `TJvFormStorage` from `JVCL` but it doesn't work correctly. It just store the forms size correctly, not with the forms position.. – Jessie M Mar 18 '13 at 10:20
  • u still did not answered, what is saved in INI file actually, when the form is closed ? is it save or restore being wrong ? – Arioch 'The Mar 18 '13 at 10:24
  • @Arioch'The Both save and restore are being wrong.. It just correctly save the forms size.. – Jessie M Mar 19 '13 at 06:44
  • so what is saved in ini file ? can u quote it ? http://www.catb.org/esr/faqs/smart-questions.html#beprecise – Arioch 'The Mar 19 '13 at 07:11
  • @Arioch'The I need to save the `TForm.Top` and `TForm.Left` properties to store the last form position correctly when the program is closed or terminated. This is the saved values in INI file by the `TJvFormStorage` : **[fmTest] FormVersion=0 ShowCmd=1 Flags=0 PixelsPerInch=96 MinMaxPos(1440x900)=-1,-1,-1,-1 MinMaxPos=-1,-1,-1,-1 NormPos(1440x900)=135,734,623,1367 NormPos=135,734,623,1367** – Jessie M Mar 19 '13 at 10:16
  • Thjat looks as normal ini, then please go into RestorePlacement and trace it and see where it goes off the rails. – Arioch 'The Mar 19 '13 at 12:56
  • @Arioch'The I've been try to use the OnRestorePlacement event but I don't understand how to do that. The OnRestorePlacement doesn't give the most obvious parameters for do a tracing.. – Jessie M Mar 20 '13 at 04:10
  • @Arioch'The I try your sugestion about adding Integer properties on `StoredValues` and it worked correctly.. Thanks a lot for your answer. Regards! – Jessie M Mar 20 '13 at 04:52
  • Why there to be ANY parameters in OnRestorePlacement ? what parmeters there could even be (but the Sender)? i believe there are examples of using it in the demo to JVCL. However - why they are needed ? You just look at declaration of .StoredValues and u see by declaration how to read and write them and just doing it. Well, i'm glad you fixed your problem. However make sure u have safety check, or once your user will decrease display resolution, or would detach one of displays (notebok + exta monitor for example), or attach another smaller one - and your program would be out of the screen! – Arioch 'The Mar 20 '13 at 13:13
  • @Arioch'The How to make a safety check as you meant? I don't understand how to do that with TJvFormStorage.. – Jessie M Mar 21 '13 at 06:54
  • Do you have `AfterRestorePlacement` event ? Edit your ini file and set form's left and right to for example 2000, 2000. Then put breakpoint into `AfterRestorePlacement` and check there, whether form's Top and LEft properties alreadywere assigned. If they were - that even is the place to check that the form has reasonable size (users would not enjoy width = 10 or like) and position (checkthat the form is visible on screen and if not - move it to proper place) – Arioch 'The Mar 21 '13 at 07:12
  • @Arioch'The Ok .. I'll try your suggestion. Thanks a lot, mate.. – Jessie M Mar 25 '13 at 02:44

1 Answers1

0

What is saved in INI file actually, when the form is closed ?

Perhaps, just perhaps, JFS takes measures to not bring the form outside the display occasionally, thus ignoring too extreme values. Try tracing INI load sequence to see on which condition it is ignored. To narrow the target, try issuing and tracing RestorePlacement method.

Now you had quoted ini file, this seems to be correct line: NormPos=135,734,623,1367 So again, add the call to aforementioned RestorePlacement and trace into it line by line. You would see either INI file is not read, or values not applied.

Most probably you would end in procedure InternalRestoreFormPlacement of JvJVCLUtils.pas. Continue tracing into it to see where and why data is either not read from INI, or fails to be assigned.

Again, even if you cannot work it out, then you have two more options:

  1. Using StoredProps property (not method) is simple: double-click the JSF component and add the Form's Left/Top/Width/Height properties to save list, uncheck form position from save list then.

  2. Using StoredValues property (not method) is simple: double-click the pproperty, then add one string property or 4 integer properties. Use the component's OnRestorePlacement and OnSavePlacement events to update them from/to the Form's actual position.

PS. Take safety measures that if a user changed display, display count or display resolution, the window would not be positioned outside the screen.

PPS. JvFormPlacement and JvFormStorage samples you can check as d:\DelphiProjects\Libs\JediVCL\jvcl\examples\JvAppStorage\*.*

PPPS. JediVCL official forum is at http://newsportal.delphi-jedi.org/index.php

Arioch 'The
  • 15,799
  • 35
  • 62