Board index » delphi » Using array to allow user to backtrack through a multi-form program

Using array to allow user to backtrack through a multi-form program

I am a beginner at this programming stuff and am trying to allow the user
to backtrack through
forms in a 19 form program using Delphi.  I was able to do this with a
Visual Basic program by using two global variables:

global last_screen(19) As String * 8
global screen_ctr As Integer

Each time the user went to the next form the screen_ctr variable would be
increased by 1.
When the user clicked on a 'return to previous screen' button the
screen_ctr would be
reduced by 1 and the previous form would appear, (throgh the use of a
sub-routine).  

My question is how to go about doing the same thing with Delphi.  I would
want to create
a global variable (array probably), and some kind of a global screen_ctr
variable, and a
subroutine which would run when the user wants to go to the previous
screen.  I basically
want to do the exact same thing I did in visual basic.  I have checked some
of my Delphi
books and haven't been able to get this to work yet.  Any hints or a rough
idea of getting this
to work would be much appreciated.  

-- Gary Lewis  

 

Re:Using array to allow user to backtrack through a multi-form program


Quote
Gary Lee Lewis wrote:
> I am a beginner at this programming stuff and am trying to allow the user
> to backtrack through
> forms in a 19 form program using Delphi.  I was able to do this with a
> Visual Basic program by using two global variables:

> global last_screen(19) As String * 8
> global screen_ctr As Integer

There is no global directive in Delphi. Everything is unit (module)
based. To create global variables that everything in your program can
see, put them in the interface section of a unit that every other unit
uses. "Globals.pas" has a certain obviousness to it ....

Quote
> Each time the user went to the next form the screen_ctr variable would be
> increased by 1.
> When the user clicked on a 'return to previous screen' button the
> screen_ctr would be
> reduced by 1 and the previous form would appear, (throgh the use of a
> sub-routine).

> My question is how to go about doing the same thing with Delphi.  I would
> want to create
> a global variable (array probably), and some kind of a global screen_ctr
> variable, and a
> subroutine which would run when the user wants to go to the previous
> screen.  I basically
> want to do the exact same thing I did in visual basic.  I have checked some
> of my Delphi
> books and haven't been able to get this to work yet.  Any hints or a rough
> idea of getting this
> to work would be much appreciated.

Try a TList.

--

Personal Pages              http://www.midnightbeach.com/jon
Programming Publications    http://www.midnightbeach.com/jon/pubs
Homeschool Resource Page    http://www.midnightbeach.com/hs

Re:Using array to allow user to backtrack through a multi-form program


On Sun, 07 Sep 1997 11:40:43 -0700, Jon Shemitz

Quote
<j...@midnightbeach.com> wrote:
>Gary Lee Lewis wrote:

>> I am a beginner at this programming stuff and am trying to allow the user
>> to backtrack through
>> forms in a 19 form program using Delphi.  I was able to do this with a
>> Visual Basic program by using two global variables:

<snip>

Quote
>Try a TList.

I'm not much of a Delphi fundi, but I would suggest doing the
Globals.pas (and adding GLOBALS to the uses clause in all the units
you want this code to work)

Then create a simple stack with two functions, one push and one pop.
The Variable could be a TList as suggested,  (Actually, I use a
TStringList for some reason :-) ))

Here is some code :

{***********************************************************************
 These functions create a sort of Stack of screen numbers. When the
 user changes screen, the last screen simply Pushes itself onto
 the stack. When the user EXITS a screen, simply POP the last number
 and display that screen. This allows the user to access same screens
 from different places and always return from whence they came.
 [A rather long explanation for the simplest piece of code in the
   program isn't it?]
***********************************************************************}
Procedure PushScreen(nScreenNum: Integer);
begin

     // Convert to a nice String and place it at the bottom!
     slScreenList.Add(IntToStr(nScreenNum));

end;

Function PopScreen : Integer;
var
    tempN      : Integer;
begin

     // if there is nothing in the stack, then go to the MAP SCREEN
     if (slScreenList.Count <= 0) then result := 5
     else
        begin
           // take the last one
     tempN := StrToInt(slScreenList.Strings[slScreenList.Count - 1]);
           // and delete it
           slScreenList.Delete(slScreenList.Count - 1);
           result := tempN;
        end;

end;

//*************************

At the begining of the program (Basically when the main form is
created) I have a :

   slScreenList := TstringList.Create;

And at the end of the program (When the last screen closes) I have :

slScreenList.Free;

And in the global.pas I have

slScreenList    : TStringList;

Easy enough, when ever I open a new screen, I simply Push the current
screen number to a stack, when ever I close a screen, I simply Pop the
last number and open that screen.

Hope that helps. Probably not the nicest way of doing it, but it might
work

Chris

Other Threads