准备开源两个delphi组件,想听听大家的意见

自己写的组件中最有价值的两个,一个叫TFieldEdit,一个叫TSQLCmd

准备开源两个delphi组件,想听听大家的意见_第1张图片

上面图中的Edit, ListBox, Memo其实都同是一个组件,有统一的数据访问接口。同时TFieldEdit组件还进行数据合法性检查,比如是否required,数据类型,长度等等。支持MaskEdit,支持正则表达式验证。目前支持的数据类型有:

  TDataType = (dtString, dtInteger, dtFloat, dtMoney, dtHex, dtBinary,
               //字符串,整型,浮点型,货币,十六进制,二进制
               dtList, dtComboList, dtCheckList, dtDateStr, dtTimeStr, dtPassword, dtNumber, dtMemo,
               //单选列表,组合列表,多选列表,日期字符串,时间字符串,密码,数字,备注框
               dtDate, dtTime);
               //日期,时间

另外一个组件是TSQLCmd,目的是封装数据库的操作,贴一段代码给大家看:

单行录入:

  with SQLCmd1 do begin
    CmdStr[0] := 'NewCustomerCommit';
    CmdStr[1] := Location.ID;
    CmdStr[2] := Oper.Opid;
    CmdStr[3] := self.FETitle.TmpStr;
    CmdStr[4] := self.FEFirstName.TmpStr;
    CmdStr[5] := self.FEMiddleName.TmpStr;
    CmdStr[6] := self.FELastName.TmpStr;
    CmdStr[7] := self.FECompany.TmpStr;
    CmdStr[8] := TFunc.BoolToStr(self.CheckBoxCompany.Checked,'0','1');
    CmdStr[9] := self.FEAddress1.TmpStr;
    CmdStr[10] := self.FEAddress2.TmpStr;
    CmdStr[11] := self.FECity.TmpStr;
    CmdStr[12] := self.FEState.TmpStr;
    CmdStr[13] := self.FEZipcode.TmpStr;
    CmdStr[14] := self.FEHomePhone.TmpStr;
    CmdStr[15] := self.FEWorkPhone.TmpStr;
    CmdStr[16] := self.FECellPhone.TmpStr;
    CmdStr[17] := self.FEFax.TmpStr;
    CmdStr[18] := self.FEBirthMonth.TmpStr+self.FEBirthDay.TmpStr;
    CmdStr[19] := self.FEEmail.TmpStr;
    CmdStr[20] := TFunc.BoolToStr(self.CheckBoxReceiveAD.Checked,'0','1');
    CmdStr[21] := self.FEKnowUsWay.TmpStr;
    CmdStr[22] := self.FEOther.TmpStr;
    CmdStr[23] := FReferBy;
    CmdStr[24] := FEPrintBy.TmpStr;
    CmdStr[25] := FENote.TmpStr;
    CmdStr[26] := TFunc.BoolToStr(self.CheckBoxTax.Checked,'0','1');
    CmdStr[27] := self.FEReferralCode.TmpStr;
    CmdStr[28] := Self.FETerm.TmpStr;
    CmdStr[29] := self.FETaxCode1.TmpStr;
    CmdStr[30] := self.FETaxCode2.TmpStr;
    CmdStr[31] := self.FETaxCode3.TmpStr;
    CmdCount := 32;
    if ExecuteCommand then begin
      result := true;
      ShowStatusHintMsg('Commit OK!');
      TFieldEdit.Clear(self.PanelTop);
      SetEditDefaultValue;
      if FormStyle=fsNormal then
        ModalResult := mrOK;
    end
    else begin
      ShowStatusHintMsg('Commit Error!');
    end;
  end;

多行录入:

  with SQLCmd1 do begin
    ClearCmdData;
    //Cmd: 1-location,2-operid,3-orderno,4-invoice,5-vendor,6-end date,7-ship method,8-tracking,9-subtotal
    //     10-shipping,11-amount,12-paid by,13-note,14-serviceno,15-busitype,
    CmdStr[0] := 'NewOrderCommit';
    CmdStr[1] := FELocation.TmpStr;
    CmdStr[2] := Oper.Opid;
    CmdStr[3] := FEOrderNo.TmpStr;
    CmdStr[4] := FEInvoice.TmpStr;
    CmdStr[5] := FEVendor.TmpStr;
    CmdStr[6] := FEEndDate.TmpStr;
    CmdStr[7] := FEShipMethod.TmpStr;
    CmdStr[8] := FETrackCode.TmpStr;
    CmdStr[9] := FESubTotal.TmpStr;
    CmdStr[10] := FormatFloat('0.00',FEShipping.AsFloat);
    CmdStr[11] := FEAmount.TmpStr;
    CmdStr[12] := FEPaidBy.TmpStr;
    CmdStr[13] := FENote.TmpStr;
    CmdStr[14] := FEServiceNo.TmpStr;
    CmdStr[15] := FEServiceNo.Hint; //busitype
    CmdStr[16] := IntToStr(Round(AdvStringGridItem.ColumnSum(2,1,AdvStringGridItem.RowCount-1)));
    CmdCount := 17;
    AddCmdRow;
    //Item: 1-itemid,2-name,3-qty,4-rate,5-amount,6-tsf,7-memo,8-kind,9-orderno,10-location
    with self.AdvStringGridItem do begin
      for iRow:=1 to RowCount-1 do begin
        CmdStr[0] := 'Item';
        CmdStr[1] := GridCells[0,iRow]; //itemid
        CmdStr[2] := GridCells[1,iRow]; //name
        CmdStr[3] := GridCells[2,iRow]; //qty
        CmdStr[4] := GridCells[3,iRow]; //rate
        CmdStr[5] := GridCells[4,iRow]; //amount
        CmdStr[6] := GridCells[5,iRow]; //tsf
        CmdStr[7] := GridCells[6,iRow]; //memo
        CmdStr[8] := GridCells[7,iRow]; //kind
        CmdStr[9] := FEOrderNo.TmpStr;
        CmdStr[10] := FELocation.TmpStr;
        CmdCount := 11;
        AddCmdRow;
      end;
    end;
    if ExecuteCommandM then begin
      TFieldEdit.Clear(PanelEdit);
      self.AdvGroupBoxSpecialOrder.CheckBox.Checked := false;
      self.FEOrderNo.Clear;
      self.InitScreen;
    end;
  end;

基本上这个组件封装了所有的数据库查询和更新操作,以及事务。使得整个项目中统一数据库的访问接口。组件背后是TADOQuery


想听听大家的意见,如果没人感兴趣,就只好留着自己用了。


你可能感兴趣的:(准备开源两个delphi组件,想听听大家的意见)