cse2207/cse3007 rapid applications programming with windows week 12
TRANSCRIPT
CSE2207/CSE3007Rapid Applications
Programming with Windows
Week 12
Topics Week 12
Handling FormsMDI in DelphiMultimediaActiveXWeb developmentDeploying/distributing a Delphi
application
Creating, Closing Forms
Delphi can create all forms as the application starts (via the AutoCreate list)Application.CreateForm(TForm1, Form1) (.DPR file) CreateForm creates a new form of the type specified
by the FormClass parameter (TForm1) and assigns it to the global variable given by the Reference parameter (Form1).
The owner of the new form is the Application object. By default the form created by the first call to
CreateForm in a project becomes the main form. Main form stays open throughout the application
Creating, Closing Forms...
Or, Delphi creates some forms, others are created, shown as needed (dynamically) (Ex 1, 2, 3)
Delphi ‘Rule of Thumb’ : you are responsible for freeing any resources you allocate
frmAbout := TFrmAbout.Create(Application);frmAbout.ShowModal;frmAbout.Free; Use Release to destroy the form and free its associated
memory. Release waits until all event handlers of the form and
its components have finished executing. Event handlers of the form should use Release instead of Free.
Handling Forms
To make the form stay on top of other open windows at runtime, (for instance, the Project Manager), set the FormStyle property to fsStayOnTop.
To specify which control has initial focus in the form at run-time, use the ActiveControl property at design time.
To change focus at run time, use the SetFocus method of the component to receive focus
procedure TForm1.Timer1Timer(Sender: TObject);begin Timer1.Interval := 100; if ActiveControl <> nil then ActiveControl.Left := ActiveControl.Left + 1; end;
Creating, Closing Forms...
A form is closed by the Close method or when the user chooses Close from the system menu.
Close calls the CloseQuery method to determine if the form can close. If CloseQuery returns False, the close operation is aborted. Otherwise, the OnClose event occurs.
Use OnClose to perform special processing when the form closes. For example, the OnClose event could call an event handler to test that all fields in a data-entry form have valid contents before allowing the form to close.
Creating, Closing Forms... See Code Example screen shot for “On Close” The value of the Action parameter determines if the form
actually closes. These are the possible values of Action:Value MeaningcaNone The form is not allowed to close, so nothing
happens.caHide The form is not closed, but just hidden. Your
application can still access a hidden form.
caFree The form is closed and all allocated memory for the form is freed.
caMinimize The form is minimized, rather than closed. This is the default action for MDI child forms
Creating, Closing Forms... If a form is an SDI child form, Action defaults to
caHide. If a form is an MDI child form, the default Action is
caMinimize. To close a form and free it in an OnClose event, set
Action to caFree.procedure Tchild.FormClose(Sender: Tobject; var
Action: TCloseAction);begin
Action := caFree;end; When the main form of the application closes, the
application terminates.
MDI Applications Parent Form (1 per application)
FormStyle property (inherited from the TForm class) is fsMDIForm
Child Form(s) FormStyle property is fsMDIChild Can’t use Hide method. Or set Visible to False Are all visible by default after being auto-created
MDI specific Form methods ArrangeIcons, Cascade, Tile (in Windows menu
item) Next, Previous
MDI forms may not be called with ShowModal
MDI Applications
MDIChildCount property of a form returns the number of MDI child forms attached to the form (Example 4)
MDIChildren array holds a reference to each of the child forms Prevent multiple instances of a child form being
created (Example 5) Close all open child forms (See screen shot)
ActiveMDIChild property returns a reference to the child form which currently has focus. (See tute exercise for this week)
MDI Applications
To merge a child menu with the Parent menu, set AutoMerge Property, and number the Menu items (File, Edit, Help etc) via the GroupIndex property
MDIParent form supports Next, Previous methods Both methods change the current active Child
form
Multimedia Programming
Wave Audio with the Windows API Add MmSystem to your Delphi unit’s uses
list The PlaySound function can play sound files
on disk, or system soundsPlaySound(‘test.wav’, 0, SND_FILENAME);Playsound(‘SystemAsterisk’, 0, SND_ALIAS);For a list of system sound events, check out
‘Sounds’ in the Control PanelFind the event sound alias in the Windows
Registry, under HKEY_CURRENT_USER
Multimedia Programming...
To prevent Windows playing the default sound (when requested sound not found): PlaySound(‘MailBeep’, 0, SND_ALIAS or
SND_NODEFAULT);
SND_ASYNC allows sound to continue playing while your application executes
SND_SYNC waits until the sound has finished playing before returning to the app (default)
Check out more sound control flags for the PlaySound function in Win32 online help
Multimedia Programming...
The TMediaPlayer (System Page) Plays wave files, MIDI files, AVI videos
etc Visual interface is the media player
controller
Multimedia Programming... OnNotify event is called whenever a command is
completed, provided Notify property is True. Examine the Error and NotifyValue properties
Player.FileName := ‘Sound1.wav’;Player.Open;Player.Wait := True; //System waits while .wav playsPlayer.Play;Player.FileName := ‘Sound2..wav’;Player.Wait := True;Player.StartPos := 1000;Player.EndPos := 3000;Player.Play
Multimedia Programming... Most sound cards enable a wave file and a MIDI
file to be played simultaneously To restart the MIDI file background music:MediaPlayer.Notify := True; Thenprocedure TForm1.MediaPlayerNotify(Sender: Tobject);begin
with Mediaplayer doIF NotifyValue = nvSuccessful then begin
Position := 0; {or set AutoRewind to True}Play;
end;end;
Multimedia Programming...
CD Audio Change the DeviceType property to dtCDAudio,
then Play (button, or method)AVI Video
Change the DeviceType property to dtAVIVideo Select the file or set the filename Play (button or method) By default, displays in a separate window OR
MediaPlayer.Display := AVIPanel {A Panel}MediaPlayer.Display.Rect :=
AVIPanel.ClientRect;
Delphi and ActiveX
COM (Component Object Model) is a Microsoft specification for creating and implementing reusable components
COM objects can be created in any language, used in any Windows programming environment
A COM object is a piece of binary code that performs a particular function - contained in a .DLL or .OCX file
Access to a COM object is through its interfaceCOM objects must be registered with Windows
Using ActiveX Controls
ActiveX is a sub-set of COM An ActiveX control has a design-time interface Third-Party ActiveX controls need to be imported into
the IDE1. Component|Import ActiveX Control2. Find the ActiveX control, (note that the Palette page
field shows ActiveX) then click Install3. Accept settings on Install dialog - the control will be
installed into the Borland User’s Components package. Accept/dismiss subsequent message boxes
4. The control is now available on the ActiveX Page of the Component Palette
Web Programming
Internet components are located on the Internet page of the Component Palette
Borland provides (Professional and C/S) TClientSocket, TServerSocket
Only Client/Server: TWebDispatcher, TPageProducer,
TQueryTableProducer, TDataSetTableProducer WebBrowser Control (same as in VB6.0)
If your users have IE4, 5 then the app will work provided you register the control on the user’s machine
Otherwise, need a license from Microsoft
Web Programming...
Why build your own web browser?? Restricts Web access only to authorised (work) sites Latter is perfect for screening kids viewing(!) Can provide access to an intranet, with company
information available only for internal use e.g. data, policies, meeting schedules, social events etc
The WebBrowser Control set its Align property to alClient Click F1 on specific properties, events for online
HELP
Deploying Delphi Applications
Deployment needs to handle: Using installation programs Identifying application files Helper applications Dll locations
Delphi applications that access databases and those that run across the Web require additional installation steps beyond those that apply to general applications
Deploying Delphi Applications...
Besides the executable file, an application may require a number of supporting files, such as DLLs, package files, and help applications.
Installation programs created with Setup toolkits perform various tasks inherent to installing Delphi applications, including: copying the executable and supporting files to the host computer, making Windows registry entries, and installing the Borland Database Engine for database applications.
InstallShield Express is recommended by Borland Need to install it from the Delphi CD
Deploying Delphi Applications...
The following types of files may need to be distributed with an application:
Type File name extensionProgram files .EXE and .DLLPackage files .BPL and .DCPHelp files .HLP, .CNT, and .TOC (if used)ActiveX files .OCX (sometimes supported by a
DLL)Local table files
.DBF, .MDX, .DBT, .NDX, .DB, .PX, .Y*,
.X*, .MB, .VAL, .QBE
Deploying Delphi Applications...
Some components bundled with Delphi are ActiveX controls. The component wrapper is linked into the application’s executable file (or a runtime package), but the .OCX file for the component also needs to be deployed with the application. Components include:
Chart FX, copyright SoftwareFX Inc. VisualSpeller Control, copyright Visual Components,
Inc. Formula One (spreadsheet), copyright Visual
Components, Inc. Graph Custom Control, copyright Bits Per Second Ltd.
Deploying Delphi Applications...
ActiveX controls of your own creation need to be registered on the deployment computer before use.
Installation programs such as InstallShield Express automate this registration process.
To manually register an ActiveX control, use the TRegSvr demo application or the Microsoft utility REGSERV32.EXE (not included with all Windows versions).
DLLs that support an ActiveX control also need to be distributed with an application.
Deploying Delphi Applications...
You can install .DLL files used only by a single application in the same directory as the application.
DLLs that will be used by a number of applications should be installed in a location accessible to all of those applications.
A common convention for locating such community DLLs is to place them either in the Windows or the Windows\System directory.
A better way is to create a dedicated directory for the common .DLL files, similar to the way the Borland Database Engine is installed.
Deploying Delphi Applications...
Deploying the Borland Database Engine For standard Delphi data components to have
database access, the Borland Database Engine (BDE) must be present and accessible. See DEPLOY.TXT for specific rights and limitations on redistributing the BDE.
Borland recommends use of InstallShield Express (or other certified installation program) for installing the BDE.
InstallShield Express will create the necessary registry entries and define any aliases the application may require.
Deploying Delphi Applications...
It is possible to install only as much of the BDE as an application actually needs. For instance, if an application only uses Paradox
tables, it is only necessary to install that portion of the BDE required to access Paradox tables.
This reduces the disk space needed for an application.
Certified installation programs, like InstallShield Express, are capable of performing partial BDE installations. Care must be taken to leave BDE system files that are not used by the deployed application, but that are needed by other programs.
Deploying Delphi Applications...
InstallShield Express Presents a Setup Checklist Start by assembling related files into
‘groups’ e.g. ReadMe files in the ReadMe Files group, data files in the Data Files group, the .exe in the Program Files group
Has 3 setup types: Typical, Compact, Custom Provides ‘Directory Specifiers’ as
placeholders, which will be replaced by actual directory locations during installation
Deploying Delphi Applications...
Allows selection, customising of the user interface for installation e.g. Welcome bitmap, message Which dialogs are included: Readme, User
Information, Choose Destination, Setup Type, Select Program Folder, Progress Indicator, Reboot Computer and Launch Application
Click Run Disk Builder button Specify the disk size: CD-Rom, 1.44 etc Creates a data file for the selected settings compresses application, installation files
Deploying Delphi Applications...
At this point, you can test the installation click the Test Run button
FINALLY!! Create Distribution Media Copy to Floppy will copy all the disk images
to the selected destination e.g. floppy disks on A: drive
InstallSheild Express provides Help, Readme, Technical Support, a Tutorial
Week 12 Tutorial
Work through the two exercises on MDI applications
Adapt your current version of the Delphi Assignment so that it works as an MDI application.
Next week (Week 13) DURING YOUR TUTORIAL you are to hand in your completed Delphi 5 assignment deliverables, and a diskette with the Project files on it. Your tutor will arrange a demo time with you.