Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > Apps

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2012, 11:15 AM
Fireprufe15 Fireprufe15 is offline
Junior Member
 
Join Date: Sep 2011
Posts: 13
Default Reset button

Is there some function I could use on my reset button or New Game button to reset the program to the state it was on creation, so that I don't need to manually clear all output text, variables, arrays etc.
There is a whole lot of variables to clear and I would prefer to do it all in one go. Thank you.
Reply With Quote
  #2  
Old 01-05-2012, 11:43 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

No, there isn't... That's the problem with a not proper OO design...
clear components on the form is easy, loop through the components and see where it inherits from... For the variables it's more or less where you defined them... If it's in a published section you might be able to use RTTI for this...
Reply With Quote
  #3  
Old 02-04-2012, 02:33 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,598
Default

in the "on create" of your form, read the state of all components: buttons, label, edits, grids,etc... and store it (in a temp file or memory variable),
when you want to reset it... just restore it back using the load function from the "save form component" ....

(some components for this save/load components state)
- rxlib (component Tformstorage)
- NiceSettings http://www.priyatna.org/nicesettings.php
- Toptions http://www.webdelphi.ru/wp-content/u...ns-v.1.7.1.zip

Quote:
Originally Posted by Fireprufe15 View Post
Is there some function I could use on my reset button or New Game button to reset the program to the state it was on creation, so that I don't need to manually clear all output text, variables, arrays etc.
There is a whole lot of variables to clear and I would prefer to do it all in one go. Thank you.
Reply With Quote
  #4  
Old 02-09-2012, 05:08 PM
nikolayj123 nikolayj123 is offline
Junior Member
 
Join Date: Aug 2009
Posts: 18
Default Reset button

Hi there
To reset all you components to initial state, you need to create your form on a run time. Let say you have 2 frms Form1 and Form2 by default you project file will look like this:

program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};

{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run;
end.

now, move creation of Form2 inside of Fom1
so you project file will look like this

program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};

{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

and create Form2 from Form1 something like this

procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2, Form2);
end;

now since you creating Form2 at run time dot forget to release it from memory when close

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;

Reply With Quote
  #5  
Old 02-13-2012, 01:04 AM
Typhoonbot Typhoonbot is offline
Junior Member
 
Join Date: Nov 2010
Posts: 15
Default

Hello Ive just created a reset button for my application as sometimes older games etc would move it to undesirable places on any one of my 4 monitors for some strange reason

Anyway, all I did with my reset button was terminate the whole application, and then relaunch it from the beginning. If this will work for you (ie. you dont need to keep global / local variables for high scores in your game etc.) then here is the simple code to destroy and recreate your app:

Code:
Application.Terminate;
    ShellExecute(Application.Handle,'Open',PChar(Application.ExeName),nil,nil,SW_NORMAL);

Regards
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:23 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.