Set the footer of dbgrideh

Source: Internet
Author: User

{*************************************** ****************}
{}
{Set footer}
{}
{Copyright (c) 2007 yongnan Studio (Chen XinGuang )}
{}
{*************************************** ****************}

// ================================================ ==========================================================
// Obtain the total value of footer pdbgrid. Columns [1]. footer. sumvalue
// For example, convert the amount into uppercase letters.
// ================================================ ==========================================================

Unit ufooter;

Interface

Uses
Sysutils, graphics, classes, dbgrideh;

// ================================================ ==========================================================
// Aflag = 1 record count
// Aflag = 2 Total
// Aflag = 3 both need
// ================================================ ==========================================================

Procedure setdbgridehfoot (pdbgrid: tdbgrideh; pcfields: string; aflag: integer = 3 );

Implementation

// ------------------------------------------------------------------------------
// function: converts a string separated by a specified separator to a string list.
// This function requires
// parameter:
// pcstring: string; string
// pcchar: string; separator
// pdeslist: tstringlist string list
// example:
// var tmpfldlist: tstrings;
// begin
// tmpfldlist: = tstringlist. create;
// strtostringlist (uppercase (pcfields), ',', tmpfldlist);
//......
// tmpfldlist. free;
// end;
// ------------------------------------------------------------------------------

Procedure strtostringlist (pcstring, pcchar: string; pdeslist: tstringlist );
VaR
Caddstr, csrcstr: string;
NPOs: integer;
Begin
Pdeslist. Clear;

Csrcstr: = pcstring;
While true do
Begin
NPOs: = pos (pcchar, csrcstr );
If NPOs = 0 then begin
Pdeslist. Add (csrcstr );
Exit;
End
Else begin
Caddstr: = copy (csrcstr, 1, NPOs-1 );
Pdeslist. Add (caddstr );
Delete (csrcstr, 1, NPOs + Length (pcchar)-1 );
End;
End;
End;

//--------------------------------------------------------------------------------
// Function: sets the total row information of dbgrideh.
// Parameter: pdbgrid: tdbgrideh;
// Pcfields: string; Field List separated by commas
// Pvttype: tfootervaluetype; Statistical type: tfootervaluetype = (fvtnon, fvtsum, fvtavg, fvtcount, fvtfieldvalue, fvtstatictext );
// Reference: strtostringlist
// For example, dbgridehfoot (dbgrideh1, 'number, Sum', fvtsum); set the quantity and amount fields as the total statistics
// Aflag = 1 record count
// Aflag = 2 Total
// Aflag = 3 both need
//--------------------------------------------------------------------------------
Procedure setdbgridehfoot (pdbgrid: tdbgrideh; pcfields: string; aflag: integer = 3 );
VaR
Nfldloop: integer;
Cfieldname: string;
Tmpfldlist: tstringlist;
Begin
If pdbgrid. Columns. Count = 1 then exit; // only one column is not set to footer.
Pdbgrid. sumlist. Active: = true;
If aflag = 1 then // number of records
Begin
Pdbgrid. footerrowcount: = 1;
Pdbgrid. Columns [0]. footer. valuetype: = fvtstatictext;
Pdbgrid. Columns [0]. footer. Value: = 'number of records ';
Pdbgrid. Columns [1]. footer. valuetype: = fvtcount;
End;
If aflag = 2 then // total
Begin
Pdbgrid. footerrowcount: = 1;
Pdbgrid. Columns [0]. footer. valuetype: = fvtstatictext;
Pdbgrid. Columns [0]. footer. Value: = 'Total ';
Tmpfldlist: = tstringlist. Create;
Try
Strtostringlist (uppercase (pcfields), ',', tmpfldlist );
For nfldloop: = 0 to pdbgrid. Columns. Count-1 do
Begin
Cfieldname: = pdbgrid. Columns [nfldloop]. fieldname;
If tmpfldlist. indexof (uppercase (cfieldname)> = 0 then
Begin
Pdbgrid. Columns [nfldloop]. footer. valuetype: = fvtsum;
End;
End;
Finally
Freeandnil (tmpfldlist );
End;
End;
If aflag = 3 then // both
Begin
Pdbgrid. footerrowcount: = 2;
Pdbgrid. Columns [0]. footers. insert (0 );
Pdbgrid. Columns [0]. footers. insert (1 );
Pdbgrid. Columns [0]. footers [0]. valuetype: = fvtstatictext;
Pdbgrid. Columns [0]. footers [0]. Value: = 'number of records ';
Pdbgrid. Columns [0]. footers [1]. valuetype: = fvtstatictext;
Pdbgrid. Columns [0]. footers [1]. Value: = 'Total ';
Pdbgrid. Columns [1]. footers. insert (0 );
Pdbgrid. Columns [1]. footers [0]. valuetype: = fvtcount;
Tmpfldlist: = tstringlist. Create;
Try
Strtostringlist (uppercase (pcfields), ',', tmpfldlist );
For nfldloop: = 0 to pdbgrid. Columns. Count-1 do
Begin
Cfieldname: = pdbgrid. Columns [nfldloop]. fieldname;
If tmpfldlist. indexof (uppercase (cfieldname)> = 0 then
Begin
Pdbgrid. Columns [nfldloop]. footers. insert (0 );
Pdbgrid. Columns [nfldloop]. footers. insert (1 );
Pdbgrid. Columns [nfldloop]. footers [1]. valuetype: = fvtsum;
End;
End;
Finally
Freeandnil (tmpfldlist );
End;
End;
End;

End.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.