修改类别(类写法)

类写法:

1,定义自动加载类别值到combobox下拉框里

unit UAutoUpdateCombox;

interface
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Data.DB, Data.Win.ADODB,
  Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Clipbrd, Vcl.Menus,
  Vcl.StdCtrls, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh,
  EhLibVCL, GridsEh, DBAxisGridsEh, DBGridEh,EhLibADO, Vcl.Buttons;

type TAutoUpdateCombox=class
  public
  class procedure autoadoqfieldstocombox(var combox:TComboBox;SAdq:TADOQuery);
end;

implementation

uses Uleibie;
class procedure TAutoUpdateCombox.autoadoqfieldstocombox(var combox:TComboBox;SAdq:TADOQuery);
 var
  i: Integer;
  List: TStringList;
begin
 List := TStringList.Create;
try
  //刷新前全部清空原来的列表
  combox.Items.Clear;
  {建立 List}
  List.Sorted := True;           {指定排序}
  List.Duplicates := dupIgnore;  {避免重复}

  {把数据加入到 DBComboBox1}

    List.Clear;
    SAdq.open;
    SAdq.First;
    while not SAdq.Eof do
    begin
      List.Add(SAdq.FieldByName('类别').AsString);
      SAdq.Next;
    end;

    //把获取到的值加载给combbobox的下拉选项里
    combox.Items:=List;
    //刷新数据库
    SAdq.Requery;
finally
   List.Free;
end;
  end;

end.

 

 

2,定义单击确定,更新客户选的combobox的类别值到access数据库里

 

unit UUpdateLeiBie;

interface
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Data.DB, Data.Win.ADODB,
  Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Clipbrd, Vcl.Menus,
  Vcl.StdCtrls, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh,
  EhLibVCL, GridsEh, DBAxisGridsEh, DBGridEh,EhLibADO, Vcl.Buttons;

type TUpdateLeiBie=class
  public
  class procedure updateselectedleibie(var combox:TComboBox; SAdq:TADOQuery);
end;

implementation

uses FDataPool;
class procedure TUpdateLeiBie.updateselectedleibie(var combox:TComboBox; SAdq:TADOQuery);
var
MyAdoq:TADOQuery;
LeiBie,SBiao: string;
begin
  MyAdoq := TADOQuery.Create(nil);
  SBiao:=copy(SAdq.name,4,length(SAdq.name)-3);
  try
    MyAdoq.Connection := frmDataPool.ADOConnection1;
    LeiBie:=combox.text;
    with MyAdoq do
    begin
      Close;
      SQL.Text := 'UPDATE '+SBiao+' SET 类别 ='+ LeiBie.QuotedString+'where 选中 = true';
      ExecSQL;
    end;
    //防止程序假死
    Application.ProcessMessages;

    //刷新纪录
  SAdq.Requery;

  finally
    MyAdoq.Free;
  end;

end;

end.

 

3.类引用使用

unit Uleibie;

interface

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Data.DB, Data.Win.ADODB,
  Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Clipbrd, Vcl.Menus,
  Vcl.StdCtrls, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh,
  EhLibVCL, GridsEh, DBAxisGridsEh, DBGridEh,EhLibADO, Vcl.Buttons;

type
  TFleibie = class(TForm)
    Label1: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ComboBox1: TComboBox;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Fleibie: TFleibie;

implementation

{$R *.dfm}

uses FDataPool, 日常管理助手, UInitializeDatabaseAdoSqlApi,
  UAutoUpdateCombox, UUpdateLeiBie;

procedure TFleibie.BitBtn1Click(Sender: TObject);
begin
//更新类别值到access数据库中
 TUpdateLeiBie.updateselectedleibie(ComboBox1,frmDataPool.qry需要做的事);
end;




procedure TFleibie.FormCreate(Sender: TObject);
begin
//更新adoquery里面的fields值到combobox的item里;
TAutoUpdateCombox.autoadoqfieldstocombox(ComboBox1,frmDataPool.qry需要做的事);
end;

end.

 

转载于:https://www.cnblogs.com/ddxxxb/p/7069995.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The history of the EhLib library -------------------------------- Version 6.1 + A new component TDBVertGridEh - DataSet Grid with the Vertical Orientation. The component is used to display and edi t a single record of DataSet in a vertical orientation. Basic properties of the TDBVertGridEh: Rows: TDBVerGridRows - A collection of items of TFieldRowEh type to display fields of a record. This is analogous to the Columns collection in TDBGridEh. Options: TDBVHGridOptions - Configure basic properties of the vertical grid. RowsDefValues: TFieldRowDefValuesEh - default values for line Grid row - TFieldRowEh. This is analogous of ColumnDefValues in TDBGridEh. GridLineParams: TDBVertGridLineParamsEh - Color settings of the dividing lines in vertical grid. DataColParams: TDBVertGridDataColParamsEh - The setting of the column with data. LabelColParams: TDBVertGridLabelColParamEh - The setting of the column with row label. See an example of using TDBVertGridEh in a project: <EhLib Archive> \ Demos \ DBVertGridEh.SimpleDemo \ Project1.dpr compiled project: <EhLib Archive> \ Demos \ Bin \ DBVertGridEh.SimpleDemo.Exe * There are changes in the grids inheritance tree: New inheritance tree is: TCustomControl | - TCustomGridEh | - TCustomDBAxisGridEh | - TCustomDBGridEh | | | - TDBGridEh | - TCustomDBVertGridEh | - TDBVertGridEh * Some constants and procedures are moved from the module DBGridEh to the DBAxisGridsEh. + Added a new global function to display a ObjectInspector-like Form. Use the next procedure to display the ObjectInspector-like Form: procedure ShowObjectInspectorForm ( Component: TObject; // A component to Inspect FormBounds: TRect; // Form Borders NewForm: Boolean = False // Show as a new Form ); This is a simple ObjectInspector that can be used to debug property setting at run-time. See an example that shows how to use ShowObjectInspectorForm here: <EhLib Archive> \ Demos \ ObjectInspectorForm.SimpleDemo \ Project1.dpr compiled project: <EhLib Archive> \ Demos \ Bin \ ObjectInspectorForm.SimpleDemo.Exe In DBGridEh + Added an ability to change the size of RowDetailPanel by mouse at RunTime. New properties in RowDetailPanel: property VertSizing: Boolean - Show an RowDetailPanel Splitter at the buttom of the RowDetailPanel. property MinHeight: Integer - Minimum height of the RowDetailPanel. property MaxHeight: Integer - Maximum height of the RowDetailPanel. property SizingBarBeveled: Boolean - Splitter area has a 3D border. property SizingBarHeight: Integer - The height of the Splitter. + Added an ability to darken gray the grid while the data is loading. See StartLoadingStatus and FinishLoadingStatus methods in the TDBGridEh. See the example that shows this opportunity in a project: <EhLib Archive> \ Demos \ DBGridEh.LoadingStatus \ Project1.dpr compiled project: <EhLib Archive> \ Demos \ Bin \ DBGridEh.LoadingStatus.Exe
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值