From: pf@bilbo.bio.purdue.edu (Paul Furbacher)
Subject: Re: tpvision question
Organization: Purdue University
Distribution: comp.lang.pascal
Date: Thu, 15 Oct 1992 05:39:55 GMT

In article <Bw45ov.KvC@watserv1.uwaterloo.ca>, nowinski@watserv1.uwaterloo.ca (NOWINSKI A - OPTOMETRY ) writes:

> I am posting those questions for my 12 years old son.
>... What do I do
>    to keep the data from the input line after someone has typed
>    something. I want it to work like this:
>...[lots of code deleted ...]

First, since you want to "transfer" the string data from one 
dialog to another (I'm assuming you want to open the "Results"
dialog after closing the "Input" dialog in order to check 
on the results) define a global string[80] called something 
like "ResultStr" (see below for its use).  Also add a submenu
item which will allow you to open the "Results" or as you title
it, "Your Data Is...", dialog box (again, see below).

> procedure DemoApp.HandleEvent(var Event: TEvent);
> 
> procedure InputData;
> var
>   D: PDialog;
>   Control: PView;
>   R: TRect;
> 
> begin
>   R.Assign(0, 0, 35, 11);
>   D := New(PDialog, Init(R, 'Data'));
>   with D^ do
>   begin
>     Options := Options or ofCentered;
> 
>     R.Assign(12, 8, 22, 10);
>     Insert(New(PButton, Init(R, 'O~K', cmOk, bfDefault)));
> 
>     R.Assign(3, 3, 32, 4);
>     Control := New(PInputLine, Init(R, 80));
>     Insert(Control);
>     R.Assign(2, 2, 15, 3);
>     Insert(New(PLabel, Init(R, '~T~ype Name', Control))); 
> 
> end;

****
>   if ValidView(D) <> nil then
>   begin
>     Desktop^.ExecView(D);
****
{ 
   Instead, you might try: 
      if DeskTop^.ExecView(ValidView(D)) <> cmCancel 
        (* don't save input if dialog D was cancelled *)
        ResultStr := PString(D^.Control^.Text)^;
        (* then dispose of the dialog box: *)
        (* dispose *after* retrieving data *) 
}

>     Dispose(D, Done);
> 
> end;
> end;
>... [more deleted]
> 
> procedure DemoApp.InitMenuBar;
> var
>   R: TRect;
> begin
>   GetExtent(R);
>   R.B.Y := R.A.Y + 1;
>   MenuBar := New(PMenuBar, Init(R, NewMenu(
> 
>     NewSubMenu('~F~ile', hcNoContext, NewMenu(
>     NewItem('~D~ata', '',kbnokey,cmInputData, hcNoContext,

****
{ insert another item which allows you to open the "Results"
  dialog: see below for comments relating to "Results" }
****

>     NewItem('E~x~it', 'Alt-X', KBAltX, cmQuit, hcNoContext,
> nil))),nil))));
> end;
> 
> procedure DemoApp.InitStatusLine;
> var
>   R: TRect;
> begin
>   GetExtent(R);
>   R.A.Y := R.B.Y - 1;
>   New(StatusLine, Init(R,
>     NewStatusDef(0, $FFFF,
>       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
>       NewStatusKey('', kbF10, cmMenu,
> 
> 
>       nil)),
>     nil)));
> end;
> 
> var
>   DemApp: DemoApp;
> 
> begin
>   DemApp.Init;
>   DemApp.Run;
>   DemApp.Done;
> end.


Next you describe your "Results" dialog.


>    var
>      D: PDialog;
>      Control: PView;
>      R: TRect;
> 
>    begin
>       R.Assign(0, 0, 40, 13);
>       D := New(PDialog, Init(R, 'Your Data is'));
>       with D^ do
>    begin
>       Options := Options or ofCentered;
> 
>       R.Grow(-1, -1);
>       Dec(R.B.Y, 3);

****
>       Insert(New(PStaticText, Init(R,
>         #13 +
>         ^C'   ')));  {There where the big space is I would like
>                       the user data to be shown}

{ Try: 

       Insert(New(PStaticText, Init(R,^C+ResultStr)));

  I'm not sure that you want a carriage return (#13) as the 
  first character of the string.  If you want to have the 
  static text centered in the dialog box, then do the following:
 
        R.Assign(0,0,X,Y); (* you decide on the size,    *)
                           (* it can wrap if you give it *)
                           (* more than one line         *)
        theText := (New(PStaticText, Init(R,^C+ResultStr));
        theText^.Options := theText^.Options or ofCentered;
        Insert(theText);

   Make sure you declare "theText : PStaticText;".
}

****
> 
>     R.Assign(14, 10, 24, 12);
> 
>     Insert(New(PButton, Init(R, 'O~K', cmOk, bfDefault)));
> 
>   end;
> 
>   if ValidView(D) <> nil then
>   begin
>     Desktop^.ExecView(D);
>     Dispose(D, Done);
>   end;
> end;

After this dialog is closed you don't care about getting 
data out of it.  

One suggestion.  Print out most or all of the demo code in
the two subdirectories called TVISION and TVDEMOS.  When
programming, use the search-inside-of-files utility provided
on the distribution diskettes, called GREP.  It takes some 
getting used to as far as knowing how to set up the options 
for searching and displaying, but it will repay huge dividends 
in being able to locate examples of how TV objects and their 
descendents have been used and created. 

Study the examples a lot.  They will give you hints as to 
how one solves these kinds of problems.

Have fun.  It looks like a good start.

PF

Newsgroups: comp.lang.pascal