Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rapid Applications Programming with Windows Week 11.

Similar presentations


Presentation on theme: "Rapid Applications Programming with Windows Week 11."— Presentation transcript:

1 Rapid Applications Programming with Windows Week 11

2 Topics Week 11 zTQuery Components (from Week 10) zCreating Reports in Delphi 5 yQuickReport zInterface Techniques ySplash screen yTooltips yBitmaps

3 TQuery Components zUsually result in more efficient processing yspecify DataBaseName, SQL statement at design time yset Active to True, RequestLive for updateable data yAt run-time e.g. in the FormCreate Event: Query1.SQL.Clear; Query1.SQL.Add(‘Select Name, Capital from CountryTable’); Query1.Open;

4 TQuery Components zUse ExecSQL for SQL statements which do not return records: Query1.SQL.Clear; Query1.SQL.Add(‘insert into CountryTable’); Query1.SQL.Add(‘ (Name, Capital) ‘); Query1.SQL.Add(‘ (values (“Australia”, “Canberra”) ’); Query1.ExecSQL; zCan also build up the query as a string, then ‘Add’ the whole string var query: string query := query + ‘Select * from Orders where ‘; etc

5 TQuery Components Using Parameters in SQL statements: zAt design time, the SQL statement is select * from CountryTable where name = :ParCountry; zAt run-time e.g. OnExit event of the edit control With Query1 do begin DisableControls; Close; ParamByName(‘ParCountry’).AsString := edtCountry.Text; Open; EnableControls; end;

6 TQuery components zUse the Datasource property to automatically link to another datasource and access any matched- name fields, which can be used as parameters in the SQL for the Query. zUseful in master/detail forms. E.g. ytable1/ds1 accesses the customer table, yquery1/ds2 retrieves orders which match the CustNo of the ‘current’ customer record: (CustNo is a foreign key in the orders table) yset the Datasource property of the Query to point to ds1 :CustNo becomes the parameter for the query ySQL property of the Query is: select * from orders where orders.CustNo = :CustNo;

7 QuickReport zQuickReport 3.0 Standard (limited) edition is included with Delphi 5 yDemo program qr3demo.exe zFor the Professional version, see http://www.qusoft.com y$99/license, 50% discount for students, unis yComplete user documentation available to registered users yWeb site provides FAQ, technical support, message board, free downloads, tutorials

8 QuickReport zTightly integrated with Delphi 5 ya QReport tab on the palette, providing components with properties, events, and On-line Help yFile|New Page -> Report module (not recommended!) yFile|New, then Forms Page->labels, list, master/detail yFile|New, then Business Page -> QuickReport Wizard yWorks with the BDE to retrieve data from DB tables: but not from Access tables in the Standard Edition yA QuickReport ‘form’ uses the Forms Designer, behaves like a Delphi form e.g. frmReport.Show; yAllows user to preview, print the report from within the Delphi application

9 QuickReport zQuickReport features: yFull preview feature while designing yCreates reports from database tables, queries, text files etc yAllows printing of labels, database fields, calculations, memo fields, pictures, icons and shapes yUses any Windows font, size, style and color yReports can be saved to file for later printing yEvent handlers can be attached to most parts of the report for further control

10 QuickReport zThe report consists of ‘bands’ each with a particular purpose e.g. a Page Header, Page Footer, Column Header, Summary etc zData displayed can come from any DataSource, including TTable, TQuery and from lists, arrays, text files (use the OnNeedData event) zProvides Master/Detail report features zSupports ‘groupings’ of data with unlimited levels, totals at each level zAutomatically perform calculations like summary and counting of fields. You can reset calculations at group level. zProvides a component for printing system data e.g. page number, date, time, report title

11 QuickReport zA report consists of y1 QuickRep component xTransforms the Delphi form into a report drop a QuickRep component onto a form xProperties, Methods and Events relate to the whole report xAlso created via File|New->Report (not preferred) y1->n QRBands xthe BandType property specifies which part of the report the band is attached to, which in turn determines the type of data the designer will display in it

12 QuickReport QRBand BandTypes: zrbPageHeader yPage Header band, printed automatically at the top of each page yPrinting on first page depends on the setting of the TQuickRep.Options.FirstPage Header property yMultiple such bands are printed in design order zrbTitle yReport title band, printed automatically, once at the beginning of the report, just after the Page Header yCan have several for successive headings yPrinted in design order

13 QuickReport zQRBand BandTypes: zrbColumnHeader yLike the Page Header yPrinted automatically on top of every column for each page zrbDetail yspecifies what is printed for each record in the report’s master dataset yeffectively ‘replicated’ for each record ycan have many rbDetail bands in a report yprinted automatically

14 QuickReport zQRBand BandTypes: zrbPageFooter yautomatically printed at the end of each page. yPrinting on last page depends on TQuickRep.Options.LastPageFooter property zrbSummary yAutomatically printed at the end of a report after all detail bands yCan be more than one

15 QuickReport QRBand BandTypes: zrbGroupHeader yFor printing information at the beginning of a new group e.g. the group identification: City: Melbourne yUsed in a Master/Detail report, a ‘grouped’ report yMust be linked to a QRGroup or a QRSubDetail component to be printed zrbGroupFooter yfor printing information at the end of a group of records eg. Total Customers in Melbourne: 23 yas for rbGroupHeader

16 QuickReport QRBand BandTypes: zrbSubDetail yused as special band type by the QRSubDetail component, which acts as a band yused for printing the detail table’s data in a master/detail report y do not set this band type manually zrbOverlay yOverlays all other bands, positioned from top left corner (NOT USED IN QR3 - included for backward compatibility)

17 QuickReport Design Elements Components for static display ylabels, images, shapes, text yvery similar to the standard VCL components zComponents for the display of data from a dataset e.g. a database yQRDBText, QRDBImage, QRDBRichText yusually placed on the detail band of a report zComponents with specialised functions yQRSysData: display date, time, page number etc yQRExpr: define, display calculated results e.g. Average, Count, Sum etc DisplayFormat property formats data

18 QuickReport: Creating Reports zStart with one QuickRep component yEffectively the ‘canvas’ where you place the elements that the report will display ysome properties affect how the report will appear when printed: Page, PrinterSettings, Options yDataset property points to the TTable or TQuery where the report will get its data from (+-Filter) ymethods Preview, Print e.g. Form2.QuickRep1.Preview yDouble-Click on the QuickReport canvas to invoke the Report Settings dialog - combines many of the other properties in one place

19 QuickReport: DB Data in Reports zDrop a TTable or TQuery component onto the report zSet DatabaseName, then TableName/SQL, then Active = True yAdd all required fields via the Fields Editor ynow set the Dataset property of the QuickRep component to point to the TTable/TQuery zCreate a Detail band: expand the Bands property of the Quickrep component, then set HasDetail to True zPlace data-aware Report components on the detail band e.g. QRDBText, and link them to the TTable/TQuery via the DataSet and DataField properties

20 QuickReport: A Simple List Report zPageTitle band showing the report title, what data is displayed e.g. Sales figures for January, yQRSysData component to display e.g. date, time of report. Text is printed before the Data e.g. Page 1 yQRSysData can display the Report Title defined in the QuickRep component zDetail band which repeats for each record in the dataset yUse QRDB…components zSummary band with totals yUse a QRExpr component, and define totals via the Expression Wizard (access via theExpression property)

21 QuickReport: Reports with Groups zRecords must be ‘ordered’ according to the group field e.g. City, Company, Date zGroup field can be a table index ySet the IndexName property of a TTable component zOr write SQL for a TQuery component to sort the records for the dataset zQuickReport provides a GroupHeader band and a GroupFooter band for printing of data before and after the group detail records

22 QuickReport: Reports with Groups zTo create a ‘Grouped’ Report: yAdd the QRGroup component, set its Expression property to the field/expression that the data will be grouped on e.g. xCity OR xCOPY(Table1.Company, 1,1) // extract 1st Char yBy default, a Group Header Band has been created, with its Master property pointing to the QuickReport component yCreate a Group Footer Band, place e.g. a calculated total for the group on it (Use a QRExpr component, and set the ResetAfterPrinting property)

23 QuickReport: Reports with Groups zSet the FooterBand property of the Group Header Band to the new Group Footer Band. zTo ensure that a group footer band is printed on the same page as the detail information, set its LinkBand to the detail band name zSet ReprintOnNewPage on Group Header if needed zTo print a report with each record on a new page, set the ForceNewPage property of the detail band to True zRight-click the QuickReport component and choose ‘Preview Report’ to view the report at design time

24 QuickReport: Master/Detail Reports zFor each Master (e.g. Customer) record printed, all the Detail (e.g. Orders) records will be printed immediately following zEach time the current record in the master dataset changes, the new values in the linked fields are used to select corresponding records in the detail dataset zTo create a Master/Detail Report yStart with a Group Report, sorted by e.g. Custno yAdd a DataSource component pointing to the master dataset (TTable linked to Customers.db) yAdd a TTable for the detail data e.g. Orders.db ySet its MasterSource to DataSource1

25 QuickReport: Master/Detail Reports zTo create a Master/Detail Report… ySet the IndexName of the detail dataset to the field which will link the data in the two tables e.g. Custno ySet the MasterFields property of the detail dataset via the Browse button -> Field Link Designer (Custno) yAdd a QRSubDetail component (it displays as a band) to display the detail data ySet its dataset property to the detail dataset, and its Master property to the QuickReport component yPlace QR data-aware components on the subdetail band yCan create many levels of detail bands

26 QuickReport zTo sum two aggregates: yQRExpr1.Expression := Sum(Field1) yQRExpr2.Expression := Sum(Field2) yQRExpr3.Expression := Sum(Field1 + Field2) zTo print a footer only on the last page of the report: yuse a Summary Band instead, and set it’s AlignToBottom property to True. zTo suppress printing of a record: yWrite code for a band’s BeforePrint event PrintBand := CustTableTotalSales > 100; yWhen PrintBand is set to False, band will not print

27 Interface Techniques zLaunch the Splash screen from the project’s DPR file, before any of the forms are instantiated e.g. begin Application.Initialize; frmSplash := TfrmSplash.Create(Application); frmSplash.Show; frmSplash.Refresh; ……code to create all the other forms frmSplash.Free; Application.Run; end.

28 Interface Techniques zDisplay ToolTips ySpecify the Hint property for each control that a Help Hint should appear for. ySet the ShowHint property of each appropriate control to True zTo force all form controls to show the form’s Hint property, set the ParentShowHint property of all controls to True zTo enable/disable all Help Hints, set the value of the application's ShowHint property to True/False. E.g. at FormCreate: Application.ShowHint = True

29 Interface Techniques: Using Bitmaps zDrop an ImageList component onto a form zDouble-click to invoke the Image Editor zAdd images as required: note their index position in the list zUse in a menu: ySet the Images property of the MainMenu component to the ImageList, then ySet the ImageIndex property of each menu item zOr set the Bitmap property of each menu item

30 Tutorial Week 11 zFinish the Delphi 5 familiarisation exercise from last week zWork through this week’s exercises to learn how to create reports zAssignment Tasks: yCreate a Splash screen and link it to your assignment yStart work on the assignment reports


Download ppt "Rapid Applications Programming with Windows Week 11."

Similar presentations


Ads by Google