zoukankan      html  css  js  c++  java
  • FireDAC 应用 (主从表关系)



    1
    //--------------------------------------------------------------------------- 2 3 // This software is Copyright (c) 2015 Embarcadero Technologies, Inc. 4 // You may only use this software if you are an authorized licensee 5 // of an Embarcadero developer tools product. 6 // This software is considered a Redistributable as defined under 7 // the software license agreement that comes with the Embarcadero Products 8 // and is subject to that software license agreement. 9 10 //--------------------------------------------------------------------------- 11 // 这里可以通过界面的设置,生成对应的主从关系 12 unit fMasterDetail; 13 14 interface 15 16 uses 17 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 18 Dialogs, DB, StdCtrls, ExtCtrls, Grids, DBGrids, Buttons, ComCtrls, 19 fMainCompBase, 20 FireDAC.Stan.Intf, FireDAC.DatS, FireDAC.Stan.Option, FireDAC.Stan.Param, 21 FireDAC.Phys.Intf, 22 FireDAC.DApt.Intf, 23 FireDAC.Comp.Client, FireDAC.Comp.DataSet, FireDAC.Stan.Error; 24 25 type 26 TfrmMasterDetail = class(TfrmMainCompBase) 27 cdsOrders: TFDMemTable; 28 cdsOrdDetails: TFDMemTable; 29 dsOrders: TDataSource; 30 DBGrid1: TDBGrid; 31 DBGrid2: TDBGrid; 32 dsOrdDetails: TDataSource; 33 Splitter1: TSplitter; 34 adOrders: TFDTableAdapter; 35 adOrderDetails: TFDTableAdapter; 36 cmOrders: TFDCommand; 37 cmOrderDetails: TFDCommand; 38 chbFetchOnDemand: TCheckBox; 39 pnlFetchOnDemand: TPanel; 40 Button1: TButton; 41 Button2: TButton; 42 procedure cbDBClick(Sender: TObject); 43 procedure chbFetchOnDemandClick(Sender: TObject); 44 procedure Button1Click(Sender: TObject); 45 procedure Button2Click(Sender: TObject); 46 private 47 { Private declarations } 48 public 49 { Public declarations } 50 end; 51 52 var 53 frmMasterDetail: TfrmMasterDetail; 54 55 implementation 56 57 uses 58 dmMainComp; 59 60 {$R *.dfm} 61 62 procedure TfrmMasterDetail.cbDBClick(Sender: TObject); 63 begin 64 with dmlMainComp.dbMain.FetchOptions do 65 Items := Items - [fiMeta]; 66 67 cdsOrders.Close; 68 cdsOrdDetails.Close; 69 inherited cbDBClick(Sender); 70 cdsOrders.Active := True; 71 cdsOrdDetails.Active := True; 72 end; 73 74 procedure TfrmMasterDetail.chbFetchOnDemandClick(Sender: TObject); 75 begin 76 // In this mode the client dataset fetches additional packets of data as needed (for example, 77 // as a user scrolls through data, or conducts a search). 78 if chbFetchOnDemand.Checked then 79 cdsOrders.FetchOptions.Mode := fmOnDemand 80 else 81 cdsOrders.FetchOptions.Mode := fmManual; 82 if chbFetchOnDemand.Checked then 83 cdsOrdDetails.FetchOptions.Mode := fmOnDemand 84 else 85 cdsOrdDetails.FetchOptions.Mode := fmManual; 86 end; 87 88 procedure TfrmMasterDetail.Button1Click(Sender: TObject); 89 begin 90 cdsOrders.ApplyUpdates(); 91 cdsOrdDetails.ApplyUpdates(); 92 end; 93 94 procedure TfrmMasterDetail.Button2Click(Sender: TObject); 95 begin 96 cdsOrders.CancelUpdates(); 97 cdsOrdDetails.CancelUpdates(); 98 cdsOrders.Refresh; 99 cdsOrdDetails.Refresh; 100 end; 101 102 end.
  • 相关阅读:
    汉语-词语:关怀
    心理学-交流:我真的关心ta,却不知道如何表达 | 如何科学地表达关心?
    汉语-词语:关心
    汉语-词语:安慰
    医疗时鲜资讯:医疗行业未来的变革(续前篇)
    字典转模型的过程中,空值和id特殊字符的处理
    最简单的基于FFmpeg的移动端样例附件:Android 自带播放器
    创建存储过程向表中循环加入数据
    分布式事务 原理及使用范例一则
    hdu 1166
  • 原文地址:https://www.cnblogs.com/fehdd/p/6386206.html
Copyright © 2011-2022 走看看