home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
tvision
/
diag
/
orders.pas
< prev
Wrap
Pascal/Delphi Source File
|
1991-03-19
|
6KB
|
186 lines
{ Orders.pas -Order entry and dialog demonstration}
{$x+}
PROGRAM Orders;
Uses Objects, Drivers, Views, Menus, App, Dialogs, Diag;
CONST
cmAbout = 100; {About-program command number }
cmSave = 101; {Save command number (not implemented) }
cmOrder = 102; {Order-Entry command number }
TYPE
{- Order record to match order-entry dialog box }
OrderInfoRec = RECORD
OToppings: Word; {Toppings check boxes }
OSize: Word; {Size radio buttons }
OStyle: Word; {Style radio buttons }
ONumber: String[4]; {Number input box }
OName: String[64]; {Customer name input box }
OPhone: String[64]; {Customer phone input box }
END;
{-Application object }
PTheApp = ^TheApp;
TheApp = OBJECT(TApplication)
CONSTRUCTOR Init;
PROCEDURE HandleEvent (VAR Event: TEvent); virtual;
PROCEDURE InitMenuBar; virtual;
END;
VAR
Order: OrderInfoRec; { Global order (represents database) }
{-Initialize global Order variable }
PROCEDURE NewOrder;
BEGIN
WITH Order DO
BEGIN
OToppings := 0; { Change settings to affect initial }
OSize := 0; { contents of order-entry dialog }
OStyle := 0;
ONumber :='';
OName :='';
OPhone :='';
END
END;
{-Construct application object }
CONSTRUCTOR TheApp.Init;
BEGIN
TApplication.Init; {Call ancestor constructor }
NewOrder {Initialize order variable }
END;
{-Respond to various events }
PROCEDURE TheApp.HandleEvent (VAR Event: TEvent);
VAR
Result: Boolean;
{-Create and execute order-entry dialog }
FUNCTION OrderDialog: Word;
VAR
Dialog: PDialog; { Pointer to TDialog object }
V: PView; { For creating various controls }
R: TRect; { For specitying various rectangles}
C: Word; { Holds result of dialog execution }
BEGIN
{-Create the dialog object }
R.Assign(0, 0, 64, 15);
Dialog := New(PDialog, Init(r, 'Order Dialog'));
WITH Dialog^ Do
BEGIN
Options := Options OR ofCentered; {Center dialog window}
{-Create Toppings check boxes }
R.Assign(3, 2, 21, 8);
V := New(PCheckBoxes, Init(r,
NewSItem('Pepperoni',
NewSItem('Extra Chess',
NewSItem('Mushroom',
NewSItem('Anchovy',
NewSItem('Sausage',
NIL)))))));
Insert (V);
R.Assign(3, 2, 21, 3);
Insert(New(PLabel, Init(R, 'Toppings', V)));
{-Create Size radio buttons }
R.Assign(25, 3, 40, 6);
V := New(PRadioButtons, Init(r,
NewSItem('Small',
NewSItem('Medium',
NewSItem('Large',
NIL)))));
Insert (V);
R.Assign(25, 3, 40, 3);
Insert(New(PLabel, Init(R, 'Size', V)));
{-Create Style radio buttons }
R.Assign(44, 3, 61, 5);
V:= New(PRadioButtons, Init(R,
NewSItem('Thin Crust',
NewSItem('Thick Crust',
NIL))));
Insert (V);
R.Assign(44, 2, 61, 3);
Insert(New(PLabel, Init(R, 'Style', V)));
{-Create Number, Name, Phone input boxes }
R.Assign(52, 6, 61, 7);
V:= New(PInputLine, Init(r, 4));
Insert (V);
R.Assign(44, 6, 51, 7);
Insert(New(PLabel, Init(R, 'Number', V)));
R.Assign(25, 8, 61, 9);
V:= New(PInputLine, Init(R, 64));
Insert (V);
R.Assign(25, 7, 61, 8);
Insert (New(PLabel, Init(R, 'Customer Name', V)));
R.Assign(25, 10, 61, 11);
V:= New(PInputLine, Init(R, 64));
Insert (V);
R.Assign(25, 9, 61, 10);
Insert(New(PLabel, Init(R, 'Customer Phone', V)));
{- Create Cancel and OK buttons }
R.Assign(30,12, 40, 14);
Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
R.Assign(45, 12, 55, 14);
Insert(New(PButton, Init(R, 'O~k~', cmOK, bfDefault)));
END;
{-Perform dialog}
Dialog^.SetData(Order);
C:= Desktop^.ExecView(Dialog);
IF C <> cmCancel THEN Dialog^.GetData(Order);
Dispose(Dialog, Done);
OrderDialog := C {So caller can inspect result}
END;
BEGIN {TheApp.HandleEvent}
IF (Event.What = evCommand) AND (Event.Command = cmQuit) THEN
IF NOT Yes('Quit now?') THEN ClearEvent(Event);
TApplication.HandleEvent(Event);
IF Event.What = evCommand THEN
BEGIN
CASE Event.Command OF
cmAbout: AboutProgram('Order-Entry Demonstration');
cmSave: ErrorMessage(999, 'Feature not implemented');
cmORder: IF OrderDialog<> cmCancel
THEN {Save order}
ELSE NewOrder;
ELSE
Exit
END;
ClearEvent(Event)
END
END;
PROCEDURE TheApp.InitMenuBar;
VAR R: TRect;
BEGIN
GetExtent (R);
R.B.Y := R.A.Y + 1;
MenuBar := New (PMenuBar, Init(R, NewMenu(
NewSubMenu('~M~enu', hcNoContext, NewMenu(
NewItem('~A~bout','',kbNoKey, cmAbout, hcNoContext,
NewItem('~S~ave','',kbNoKey, cmSave, hcNoContext,
NewItem('~O~rder','', kbNoKey, cmOrder, hcNoContext,
NewLine(
NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoCOntext,
NIL)))))),
NIL))
))
END;
VAR
Application: TheApp;
BEGIN
Application.Init;
Application.Run;
Application.Done
END.