dac FDMemTable

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
  FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, FireDAC.UI.Intf,
  FireDAC.VCLUI.Wait, FireDAC.Phys.MSSQLDef, FireDAC.Stan.Def,
  FireDAC.Stan.Pool, FireDAC.Phys, FireDAC.Phys.MSSQL, cxGraphics, cxControls,
  cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray,
  dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, cxStyles,
  dxSkinscxPCPainter, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit,
  cxNavigator, Data.DB, cxDBData, FireDAC.Comp.Client, cxGridLevel, cxClasses,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, FireDAC.Phys.ODBCBase, FireDAC.Comp.UI, FireDAC.Comp.DataSet,
  Vcl.StdCtrls, FireDAC.Stan.StorageXML, FireDAC.Stan.StorageJSON,
  FireDAC.Stan.StorageBin;

type
  TForm1 = class(TForm)
    FDQuery1: TFDQuery;
    FDGUIxWaitCursor1: TFDGUIxWaitCursor;
    FDPhysMSSQLDriverLink1: TFDPhysMSSQLDriverLink;
    tv: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    ds1: TDataSource;
    con: TFDConnection;
    btn1: TButton;
    tvColumn1: TcxGridDBColumn;
    tvColumn2: TcxGridDBColumn;
    btn2: TButton;
    btn3: TButton;
    FDMemTable1: TFDMemTable;
    FDStanStorageXMLLink1: TFDStanStorageXMLLink;
    FDMemTable2: TFDMemTable;
    FDStanStorageJSONLink1: TFDStanStorageJSONLink;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//select * from tb_kswh
procedure TForm1.btn1Click(Sender: TObject);
begin
//  with FDQuery1  do
//  begin
//    close;
//    sql.Text:= 'select sksbm,sksmc from tb_kswh';
//    open;
//  end;

//FDQuery1.Connection:= nil;

//  FDQuery1.Close;
//  FDQuery1.FieldDefs.Clear;
//  FDQuery1.FieldDefs.Add('sksbm',ftString,50);
//  FDQuery1.FieldDefs.Add('sksmc',ftString,50);
//  FDQuery1.CreateDataSet;

  FDMemTable1.Close;
  FDMemTable1.FieldDefs.Clear();
  FDMemTable1.FieldDefs.Add('sksbm', ftString, 50, false);
  FDMemTable1.FieldDefs.Add('sksmc', ftString, 50, false);
  FDMemTable1.CreateDataSet;


//  FDMemTable1.Append;
//  FDMemTable1.FieldByName('sksbm').AsString:= '1';
//  FDMemTable1.FieldByName('sksmc').AsString:= '1aa';
//  FDMemTable1.Append;
//  FDMemTable1.FieldByName('sksbm').AsString:= '2';
//  FDMemTable1.FieldByName('sksmc').AsString:= '2bb';
//  FDMemTable1.Post;
  FDMemTable1.AppendRecord(['1', '1cc']);
  FDMemTable1.AppendRecord(['2', '2cc']);
  FDMemTable1.AppendRecord(['3', '3cc']);
  //FDMemTable1.Post;
  FDMemTable1.SaveToFile('a.xml');
   FDQuery1.LoadFromFile('a.xml');
  FDMemTable2.LoadFromFile('a.xml');
  ds1.DataSet:= FDMemTable1;
end;

procedure TForm1.btn2Click(Sender: TObject);
var
  i:Integer;
begin
//  tv.OptionsData.Editing:= true;
//  FDQuery1.Edit;
//  con.StartTransaction;
  FDMemTable1.Delete;
  FDMemTable1.SaveToFile('b.xml');
end;

procedure TForm1.btn3Click(Sender: TObject);
begin
//  FDQuery1.ApplyUpdates(0);//must
//  //FDQuery1.CommitUpdates; //no use
//  con.Commit;

  FDMemTable1.LoadFromFile('b.xml');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//  FDQuery1.CachedUpdates:= True;
//  tv.OptionsData.Editing:= false;
end;

end.

你可能感兴趣的:(dac FDMemTable)