TOMJ@csdserver3.csd.scarolina.edu (Thomas E. Jenkins, Jr.) (06/11/91)
Hi,
I haven't played with TViews enough to feel comfortable designing my own
version of TInputLine, but there is a simple solution to the problem of the
phone input. Basicly, if you turn the inputline from insert mode to
overwrite mode, TInputLine will not erase the current contents of the line.
To set the mode is very easy as demonstrated in the following code:
PROGRAM PhoneInput ;
USES
App ,
Objects ,
Dialogs ,
StdDlg ,
Menus ,
Drivers ,
Views ,
Memory ,
MsgBox ,
HistList ,
Gadgets ,
DOS ;
CONST
cmAbout = 2000 ;
cmTestInput = 2001 ;
TYPE
TVisionEX = OBJECT ( TApplication )
clock : PClockView ;
heap : PHeapView ;
CONSTRUCTOR Init ;
DESTRUCTOR Done ;
VIRTUAL ;
PROCEDURE Idle ;
VIRTUAL ;
PROCEDURE InitMenuBar ;
VIRTUAL ;
PROCEDURE InitStatusLine ;
VIRTUAL ;
PROCEDURE HandleEvent ( VAR event : TEvent ) ;
VIRTUAL ;
END ; { TVisionEX }
PInputPhone = ^TInputPhone ;
TInputPhone = OBJECT ( TInputLine )
PROCEDURE HandleEvent ( VAR event : TEvent ) ;
VIRTUAL ;
END ; { TInputPhone }
Str128 = STRING [ 128 ] ;
Str100 = STRING [ 100 ] ;
Str8 = STRING [ 008 ] ;
TInputData = RECORD
s1 : Str128 ;
s2 : Str100 ;
s3 : Str8 ;
END ; { TInputData }
VAR
data : TInputData ;
PROCEDURE About ;
VAR
dialog : PDialog ;
r : TRect ;
control : WORD ;
BEGIN { About }
r.Assign ( 20 , 5 , 60 , 14 ) ;
dialog := New ( PDialog ,
Init ( r ,
'About ... ' ) ) ;
WITH dialog^
DO
BEGIN
r.Assign ( 9 , 2 , 36 , 3 ) ;
Insert ( New ( PStaticText ,
Init ( r ,
'Turbo Vision Examples' ) ) ) ;
r.Assign ( 10 , 4 , 35 , 5 ) ;
Insert ( New ( PStaticText ,
Init ( r ,
'By Thomas E. Jenkins' ) ) ) ;
r.Assign ( 15 , 6 , 25 , 8 ) ;
Insert ( New ( PButton ,
Init ( r ,
'~O~k',
cmOk ,
bfDefault ) ) ) ;
END ; { WITH }
control := deskTop^.ExecView ( dialog ) ;
Dispose ( dialog , Done ) ;
END ; { About }
PROCEDURE TestInput ;
VAR
mem : LONGINT ;
dialog : PDialog ;
r : TRect ;
control : WORD ;
inputLine : PInputLine ;
BEGIN { TestInput }
mem := MemAvail ;
r.Assign ( 20 , 5 , 60 , 17 ) ;
dialog := New ( PDialog ,
Init ( r ,
'Input Box ... ' ) ) ;
WITH dialog^
DO
BEGIN
r.Assign ( 3 , 3 , 30 , 4 ) ;
inputLine := New ( PInputLine , { NOTE! Do not include }
Init ( r , { length byte in Init }
SizeOf ( Str128 ) - 1 ) ) ;
Insert ( inputLine ) ;
r.Assign ( 3 , 2 , 13 , 3 ) ;
Insert ( New ( PLabel ,
Init ( r ,
'Line one' ,
inputLine ) ) ) ;
r.Assign ( 3 , 5 , 25 , 6 ) ;
inputLine := New ( PInputLine , { NOTE! Do not include }
Init ( r , { length byte in Init }
SizeOf ( Str100 ) - 1 ) ) ;
Insert ( inputLine ) ;
r.Assign ( 3 , 4 , 13 , 5 ) ;
Insert ( New ( PLabel ,
Init ( r ,
'Line two' ,
inputLine ) ) ) ;
r.Assign ( 3 , 7 , 13 , 8 ) ;
inputLine := New ( PInputPhone , { NOTE! Do not include }
Init ( r , { length byte in Init }
SizeOf ( Str8 ) - 1 ) ) ;
Insert ( inputLine ) ;
r.Assign ( 3 , 6 , 15 , 7 ) ;
Insert ( New ( PLabel ,
Init ( r ,
'Phone number' ,
inputLine ) ) ) ;
r.Assign ( 2 , 9 , 12 , 11 ) ;
Insert ( New ( PButton ,
Init ( r ,
'~O~k',
cmOk ,
bfDefault ) ) ) ;
r.Assign ( 16 , 9 , 26 , 11 ) ;
Insert ( New ( PButton ,
Init ( r ,
'~C~ancel',
cmCancel ,
bfNormal ) ) ) ;
SelectNext ( FALSE ) ; { Select first item }
END ; { WITH }
dialog^.SetData ( data ) ;
control := deskTop^.ExecView ( dialog ) ;
IF ( control <> cmCancel )
THEN
dialog^.GetData ( data ) ;
Dispose ( dialog , Done ) ;
IF ( mem <> MemAvail )
THEN
BEGIN
mem := mem - MemAvail ;
MessageBox ( 'Lost %d bytes of RAM!' ,
@mem ,
mfWarning + mfOKButton ) ;
END ; { IF }
END ; { TestInput }
{**************************************************************************}
PROCEDURE TInputPhone.HandleEvent ( VAR event : TEvent ) ;
BEGIN { TInputPhone.HandleEvent }
BlockCursor ; { Set overwrite mode! }
TInputLine.HandleEvent ( event ) ;
END ; { TInputPhone.HandleEvent }
{**************************************************************************}
CONSTRUCTOR TVisionEX.Init ;
VAR
r : TRect ;
event : TEvent ;
BEGIN { TVisionEX.Init }
TApplication.Init ;
RegisterObjects ;
RegisterViews ;
RegisterMenus ;
RegisterDialogs ;
RegisterApp ;
GetExtent ( r ) ;
r.a.x := r.b.x - 9 ;
r.b.y := r.a.y + 1 ;
clock := New ( PClockView ,
Init ( r ) ) ;
Insert ( clock ) ;
GetExtent ( r ) ;
Dec ( r.b.x ) ;
r.a.x := r.b.x - 9 ;
r.a.y := r.b.y - 1 ;
heap := New ( PHeapView ,
Init ( r ) ) ;
Insert ( heap ) ;
{ Display about box }
event.what := evCommand ;
event.command := cmAbout ;
PutEvent ( event ) ;
END ; { TVisionEX.Init }
DESTRUCTOR TVisionEX.Done ;
BEGIN { TVisionEX.Done }
TApplication.Done ;
Dispose ( heap ) ;
Dispose ( clock ) ;
END ; { TVisionEX.Done }
PROCEDURE TVisionEX.Idle ;
BEGIN { TVisionEX.Idle }
TApplication.Idle ;
clock^.Update ;
heap^.Update ;
END ; { TVisionEX.Idle }
PROCEDURE TVisionEX.InitMenuBar ;
VAR
r : TRect ;
BEGIN { TVisionEX.InitMenuBar }
GetExtent ( r ) ; { Get current screen size }
r.b.y := ( r.a.y + 1 ) ; { Set to one line from top }
MenuBar := New ( PMenuBar , Init ( r , NewMenu (
NewSubMenu ( ' ~' + #240 + '~ ' , hcNoContext , NewMenu (
NewItem ( '~A~bout...' , 'Alt-A' , kbAltA , cmAbout , hcNoContext ,
NIL ) ) ,
NewSubMenu ( '~F~ile' , hcNoContext , NewMenu (
NewItem ( 'E~x~it' , 'ALT-X' , kbAltX , cmQuit , hcNoContext ,
NIL ) ) ,
NewSubMenu ( '~T~est' , hcNoContext , NewMenu (
NewItem ( '~I~nput dialog...' , '' , kbNoKey , cmTestInput ,
hcNoContext ,
NIL ) ) ,
NIL )
) ) ) ) ) ;
END ; { TVisionEX.InitMenuBar }
PROCEDURE TVisionEX.InitStatusLine ;
VAR
r : TRect ;
BEGIN { TVisionEX.InitStatusLine }
GetExtent ( r ) ; { Get screen size }
r.a.y := r.b.y - 1 ; { Set to one line from }
{ Screen size }
statusLine := New ( PStatusLine , Init ( r ,
NewStatusDef ( 0 , $FFFF , { Set context help ranges}
NewStatusKey ( '~Alt-X~ Exit' , kbAltX , cmQuit ,
NewStatusKey ( '~F10~ Menu' , kbF10 , cmMenu ,
NIL ) ) ,
NIL ) ) ) ;
END ; { TVisionEX.InitStatusLine }
PROCEDURE TVisionEX.HandleEvent ( VAR event : TEvent ) ;
VAR
r : TRect ;
BEGIN { TVisionEX.HandleEvent }
TApplication.HandleEvent ( event ) ;
IF ( event.what = evcommand )
THEN
BEGIN
CASE event.command
OF
cmTestInput :
TestInput ;
cmAbout :
About ;
ELSE
END ; { CASE }
ClearEvent ( event ) ;
END ; { THEN }
END ; { TVisionEX.HandleEvent }
VAR
ld : TVisionEX ;
mem : LONGINT ;
BEGIN
mem := MemAvail ;
data.s1 := 'This is line one.' ; { Set strings to initial }
data.s2 := 'This is line two.' ; { values. }
data.s3 := ' - ' ;
ld.Init ;
ld.Run ;
ld.Done ;
IF ( mem <> MemAvail )
THEN
WriteLn ( mem , ' - ' , MemAvail ) ; { Sanity check ;-) }
END .
tom
+--------------------------------------------------------------------------+
| Thomas E. Jenkins, Jr. Programmer, University of South Carolina CSD |
+--------------------------------------------------------------------------+
| BITNET : C0361@UNIVSCVM.BITNET | CSDNET : tomj/csdserver3 |
| INTERNET : TOMJ@csdserver3.csd.scarolina.EDU {PREFERRED} |
| : C0361@univscvm.csd.scarolina.EDU | 129.252.43.30 |
+--------------------------------------------------------------------------+