Objectives: 1) Review Delphi's Environment 2) Use Forms and Units 3) Use simple Components: EditBox, BitButtons, RadioButtons 4) Build a simple Delphi program that uses multiple forms Part 1: Build a simple program which allows the user to select the name and type of border should be displayed in a form. a) Start with a new project and name the form MainForm. b) Place a Tbutton on the form and enter the event handler shown in Listing 5.1 (pg. 87). c) Add a new form and name it OptionsForm. d) On the new form, place four radio buttons (Single Border, Dialog, No Border and Sizeable) in a Group Box named Form Style. e) Add an empty Tedit component and a Label (titled Form Caption). f) Add two TbitBtns and change their kind properties to bkOK and bkCancel. g) Save your project (and unit) as Plab1.dpr and Ulab1.pas h) Run the project and trying select a different border type and renaming the form. Part 2: Add whatever is necessary to the OptionsForm that will allow the user to select which Border Icons should be available on the MainForm. Remember that you may have none, one or more of the icons available. Part 3: Add whatever is necessary to the OptionsForm that will allow the user to select which cursor should be available on the MainForm. The user should be able to select one of the 18 pre-defined cursor types as well as the "crosshair" cursor found on the book's CD. BONUS: Create your own cursor and it to the list in part 3. Documenting your unit by inserting comments with your name, the date and a brief description at the top of the unit. Turn in to me a disk with all of the necessary files. Make sure your project name is indicated on the disk.
CS450 Lab 3 - GDI and Graphics Programming
due: Feb. 12, 1996 Objectives: 1) Further Explore Delphi's Environment 2) Creating Application using GDI and Graphics Programming 3) Print the resultant application using TPrinter Part 1: Drawing Lines a) Start with a new project. b) Create a form with the following properties and save the unit as CANVAS.PAS: ---------------------------------------------------------------------------------------- Property Value ---------------------------------------------------------------------------------------- Caption ‘Paint Canvas' Color clWhite ---------------------------------------------------------------------------------------- c) Add components to the Form that allows the user to select a Pen Color. d) Add components to the Form that allows the user to select a Pen Style. e) Add components to the Form that allows the user to select the Pen Width. f) Add components to the Form that allows the user to select a starting point and ending point for drawing a line. g) Add a PaintBox for drawing in. (Make sure that the PaintBox is sufficiently large) h) Add a button that allows the user to draw the selected line in the PaintBox. h) Add an Exit button. Part 2: "Brush Painting" a) Add components to the Form that allows the user to select a Brush Color. b) Add components to the Form that allows the user to select a Brush Style. c) Add a component to the Form that allows the user to select whether to fill in the object to be drawn. d) Add components to the Form that allows the user to select the figure (Arc, Chord, Ellipse, Pie, Polygon, Polyline, Rectangle, and RoundRectangle) to be drawn on the PaintBox. [Note each figure is going to require different parameters to be selected, i.e. if Rectangle is selected, you will have to ask the user for four values.] Part 3: Printing your BitMap a) Include a TPrinter component that will allow the contents of the PaintBox to be printed. b) Be sure to include an AbortForm (see page 307). Documenting your units by inserting comments with your name, the date and a brief description at the top of the units. Turn in to me a disk with your .PAS, .DFM and .DPR files as well as a sample of your artwork.
CS450 Lab 4 - Writing Delphi Custom Components due: Feb. 19, 1996
Objectives: 1) Explore Writing Delphi Components Part 1: Extending the TListBox Component a) Start with a new component. b) Use TTabListbox for the name of the component, TListbox for the ancestor type, and PS2 for the Palette page and save the file as LBTAB.PAS. c) Remove Graphics,Forms, Dialogs from the uses clause to improve efficiency. d) Declare the following private variables: FLongestString : Word; FNumTabStops : Word; FTabStops : PWord; FSizeAfterDel : Boolean; e) Include the uses PixDlg; clause in the implementation section and copy the uses PixDlg.pas file from the CD to your disk. f) Enter the constructor. Make sure to include override in the public section. constructor TTabListBox.Create(AOwner : TComponent); begin Inherited Create(AOwner); FSizeAfterDel := TRUE; {set tab stops to Windows defaults...} FNumTabStops := 1; GetMem(FTabStops, SizeOf(Word) * FNumTabStops); FTabStops^ := DialogUnitsToPixelsX(32) end; Include the following property in the published section: property SizeAfterDel: Boolean read FSizeAfterDel write FSizeAfterDel default True; g) Include the protected method: [Make sure to override the earlier version] procedure TTabListBox.CreateParams(var Params : TCreateParams); {OR in the styles necessary for tabs and horizontal scrolling} begin inherited CreateParams(Params); Params.Style := Params.Style or lbs_UseTabStops or ws_HScroll; end; h) Include the public method: procedure TTabListBox.SetTabStops(A : array of word); var pos : word; TempTab : word; TempBuf : PWord; begin TempTab := High(A) + 1; GetMem(TempBuf, SizeOf(A)); Move(A, TempBuf^, SizeOf(A)); for pos := 0 to TempTab - 1 do A[pos] := PixelsToDialogUnitsX(A[pos]); if Perform(lb_SetTabStops, TempTab, Longint(@A)) = 0 then begin FreeMem(TempBuf, SizeOf(Word) * TempTab); raise ETabListboxError.Create('Failed to set tabs.') end else begin FreeMem(FTabStops, SizeOf(Word) * FNumTabStops); FNumTabStops := TempTab; FTabStops := TempBuf; FindLongestString; Invalidate end; end; Declare the type ETabListboxError = class(Exception); and include the private methods: function GetLBStringLength(P : PChar); word; procedure FindLongestString; procedure SetScrollLength(P : PChar); procedure LBAddString(var Msg : TMessage); message lb_AddString; procedure LBInsertString(var Msg : TMessage); message lb_InsertString; procedure LBDeleteString(var Msg : TMessage); message lb_DeleteString; i) Write a small project to test your TabListBox. (There is an example on your disk). You will need to include your unit in the interface part and declare a variable of type TTabListBox. Your test project should include buttons for adding, deleting, inserting items in your TabListBox and a button for sorting the contents. Part 2: Creating a Marquee a) Start with a new component. b) Use TMarquee for the name of the component, TCustomControl for the ancestor type, and Samples for the Palette page and save the file as MARQUEE.PAS. c) Setup the mechanism for rendering text onto the memory canvas: i) write the SetLineHeight private method (pp. 275-6). ii) write the MakeRect private method (pg. 276) and SetItems private method iii) define private properties: MemBitmap, LineHi, VRect, FItems and FJust and the enumerated type TJustification. iv) write the PaintLine private method (pg. 277) and define the EMarqueeError type. d) Setup the mechanism that copies text from the memory canvas to the marquee window. i) write the Paint protected method (pg. 277) and the private properties InsideRect, CurrLine and FActive. ii) write the private method SetStartLine. e) Setup the timer that keeps track of when and how to scroll the window. i) write the procedure DoTimer and the private property FTimer. ii) write the methods FTimerOnTimer and IncLine and the private property FScrollDown. iii) Add the constants ScrollPixels and TimerInterval. f) Setup the constructors and destructors i) Write the class constructor Create and destructor Destroy ii) Write the methods Activate, FillBitMap, and Deactivate as well as the property FOnDone and the public property Active. g) Finishing touches:Publish the inherited properties from TCustomPanel (pg. 282). h) Write a small project to test your Marquee (There is an example on your disk). Include a button to add names / words to the Marquee list. Have the "Marquee" beep whenever it is activated.
CS450 Project 1 - Writing Delphi Custom Components due: Feb. 28, 1996
Objectives: Writing a Delphi Component Your programming team is expected to select one of the following components and create it. You will be expected to do the following: 1. Create a unit for the new component. 2. Derive the component type from an existing component type. 3. Add properties, methods, and events as needed. 4. Register your component with Delphi. 5. Create a Help file for your component and its properties, methods, and events. 6. After thorough testing, place your component in the PS2 Palette (this will include designing an icon for your component) There should also be a Hint for your component. Your completed component will include the following five files: 1. The source code unit (.PAS file) 2. The compiled unit (.DCU file) 3. A palette bitmap (.DCR file) 4. A Help file (.HLP file) 5. A Help-keyword file (.KWF file) 6. Any projects that you used for testing your component You may select one of the following components or design one of your own (must have my approval by Feb. 14th): A) A Color and Sizeable 3D button. B) 3-D Multi-colored Labels (must allow Flat, Raised, Recessed, and Shadow) C) An edit window: This would include a status bar at the bottom of the window which would consist of minimally the time, date, file name, line number and position.
CS450 Lab 5 - Sharing Information with the Clipboard and DDE due: Feb. 26, 1996
Objectives: 1) Learning how to move data between applications Part 1: Creating Your Own Clipboard Format 1) Create the following form: 2) Create the following event-handlers: procedure TForm1.CopyButtonClick(Sender: TObject); var DDGObj : TDDGObject; begin DDGObj := TDDGObject.Create; with DDGObj do begin Rec.FName := Edit1.Text; Rec.MI := Edit2.Text; Rec.LName := Edit3.Text; CopyToClipBoard end; DDGObj.Free end; procedure TForm1.PasteButtonClick(Sender: TObject); var DDGObj : TDDGObject; begin DDGObj := TDDGObject.Create; if ClipBoard.HasFormat(CF_DDGDATA) then with DDGObj do begin GetFromClipBoard; Edit1.Text := Rec.FName; Edit2.Text := Rec.MI; Edit3.Text := Rec.LName; end; DDGObj.Free end; 3) Add clipbrd to the Uses clause and define the variable CF_DDGDATA : word; 4) Create the types: PDDGRec = ^TDDGRec; TDDGRec = record LName : string; FName : string; MI : string; end; TDDGObject = class(TObject) private Rec : TDDGRec; protected procedure CopyToClipBoard; procedure GetFromClipBoard; end; 5) Create the two TDDGObject methods as shown on pages 354-5. 6) Register the clipboardformat in the initialization section: CF_DDGDATA := RegisterClipBoardFormat(‘CF_DDG'); 7) Run your program. If there are problems, view the clipboard. Part 2: Interfacing the ClipBoard with another object. 1) Add a StringGrid and EditBox to your form. 2) Replace the PasteButton event handler with one that pastes the contents of the clipboard into the stringgrid in the row designated by the contents of the EditBox.
You should know how to use the following components: TForm, TScreen, TApplication, TmainMenu, Tbutton, Tlabel, Tpanel, Tspeedbutton, Tstrings, Tcanvas, Tprinter, Dialogs, Timage, TDDEServer, TDDEClient, ToleContainer, TBitButton
DELETE FROM EMPLOYEE WHERE EMPNO = :EMPNO
INSERT INTO EMPLOYEE (EMPNO, LASTNAME, FIRSTNAME, PHONEEXT, HIREDATE, SALARY) VALUES (:EMPNO, :LASTNAME, :FIRSTNAME, :PHONEEXT, :HIREDATE, :SALARY)
UPDATE EMPLOYEE SET EMPNO = :EMPNO, LASTNAME = :LASTNAME, FIRSTNAME = :FIRSTNAME, PHONEEXT = :PHONE, HIREDATE = :HIREDATE, SALARY = :SALARY WHERE EMPNO = :EMPLOYEE_NBR
procedure TDatabase.InsRecordClick(Sender: TObject); begin Screen.Cursor := crHourGlass; try with InsertQuery do begin try Close; Prepare; Params[0].AsInteger := StrToInt(EditEmpNo.Text); Params[1].AsString := EditLastName.Text; Params[2].AsString := EditFirstName.Text; Params[3].AsString := EditPhoneExt.Text; Params[4].AsDate := StrToDate(EditHireDate.Text); Params[5].AsFloat := StrToFloat(EditSalary.Text); ExecSQL; GridQuery.Close; GridQuery.Open; except on E: EDataBaseError do MessageDlg(E.Message, mtInformation, [mbOK], 0); end; end; ClearFields; finally Screen.Cursor := crDefault; ClearFields end end;
procedure TDatabase.DelRecordClick(Sender: TObject); var EmployeeNumber : integer; begin EmployeeNumber := GridQuery.Fields[0].AsInteger; if MessageDlg(Format('Delete "%d"?', [EmployeeNumber]), mtConfirmation, mbOKCancel, 0) = mrOK then begin Screen.Cursor := crHourGlass; try with DeleteQuery do begin Prepare; Params[0].AsInteger := EmployeeNumber; ExecSQL end; GridQuery.Close; GridQuery.Open finally Screen.Cursor := crDefault end end end;
procedure TDatabase.GetRecordClick(Sender: TObject); var Count : integer; begin for count := 0 to ControlCount - 1 do begin if Controls[count] is TEdit then with TEdit(Controls[count]) do Text := GridQuery.Fields[Tag].AsString end; UpdRecord.Enabled := true end;
procedure TDatabase.UpdRecordClick(Sender: TObject); var count : integer; begin Screen.Cursor := crHourGlass; try UpdateQuery.Prepare; for count := 0 to ControlCount - 1 do begin if Controls[count] is TEdit then with TEdit(Controls[count]) do UpdateQuery.Params[Tag].AsString := Text; end; UpdateQuery.Params[0].AsInteger := StrToInt(EditEmpNo.Text); UpdateQuery.ExecSQL; GridQuery.Close; GridQuery.Open; UpdRecord.Enabled := false finally Screen.Cursor := crDefault end end;
Narrative: Your class has been assigned to develop an on-line registration system for NMHU. Your first task will be to assign duties. The project can be divided into four subtasks. The project leader will be required to develop the introductory interface which will tie into the other three parts. The project leader will also be in charge of assigning duties among the three groups and making sure that the other three parts interface nicely. The project leader will also be responsible for overseeing the databases and will need to contact me whenever there is a problem with the databases. A copy of the databases are located on my share drive in \Delphi\OnLine. [I would suggest you make a working copy of all files to the computer you are using and label the path with an alias]. The structure of the databases is shown below. Make sure all parts of your application are user-friendly and they include About boxes and Help screens.