Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:3k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   AnsiString fieldname,filename,asstype;
  18.   int nn;
  19.   double aa;
  20.   filename="test1.dbf";
  21.   asstype="T1";
  22.   Query1->Active=False;
  23.   Query1->SQL->Clear();
  24.   Query1->SQL->Add("SELECT");
  25.   Query1->SQL->Add("MAX(NUM)");
  26.   Query1->SQL->Add("From ""+filename+""");
  27.   if(CheckBox1->Checked)
  28.     Query1->SQL->Add("WHERE TYPE='"+asstype+"'");
  29.   Query1->Active=True;
  30.   nn=Query1->FieldCount;
  31.   if(nn>0)
  32.     fieldname=Query1->Fields->Fields[0]->FieldName;
  33.   aa=Query1->FieldByName(fieldname)->AsFloat;
  34.   Edit1->Text=FloatToStr(aa);
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::Button2Click(TObject *Sender)
  38. {
  39.   AnsiString fieldname,filename,asstype;
  40.   int nn;
  41.   double aa;
  42.   filename="test1.dbf";
  43.   asstype="T1";
  44.   Query1->Active=False;
  45.   Query1->SQL->Clear();
  46.   Query1->SQL->Add("SELECT");
  47.   Query1->SQL->Add("SUM(NUM)");
  48.   Query1->SQL->Add("From ""+filename+""");
  49.   if(CheckBox1->Checked)
  50.     Query1->SQL->Add("WHERE TYPE='"+asstype+"'");
  51.   Query1->Active=True;
  52.   nn=Query1->FieldCount;
  53.   if(nn>0)
  54.     fieldname=Query1->Fields->Fields[0]->FieldName;
  55.   aa=Query1->FieldByName(fieldname)->AsFloat;
  56.   Edit1->Text=FloatToStr(aa);
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::Button3Click(TObject *Sender)
  60. {
  61.   AnsiString fieldname,filename,asstype;
  62.   int nn;
  63.   double aa;
  64.   filename="test1.dbf";
  65.   asstype="T1";
  66.   Query1->Active=False;
  67.   Query1->SQL->Clear();
  68.   Query1->SQL->Add("SELECT");
  69.   Query1->SQL->Add("AVG(NUM)");
  70.   Query1->SQL->Add("From ""+filename+""");
  71.   if(CheckBox1->Checked)
  72.     Query1->SQL->Add("WHERE TYPE='"+asstype+"'");
  73.   Query1->Active=True;
  74.   nn=Query1->FieldCount;
  75.   if(nn>0)
  76.     fieldname=Query1->Fields->Fields[0]->FieldName;
  77.   aa=Query1->FieldByName(fieldname)->AsFloat;
  78.   Edit1->Text=FloatToStr(aa);
  79. }
  80. //---------------------------------------------------------------------------