首页 > 代码库 > FDMemTable的详细使用方法
FDMemTable的详细使用方法
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, Data.DB, Data.SqlExpr,
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit, System.Rtti, FMX.Layouts,
FMX.Grid, Data.Bind.EngExt, Fmx.Bind.DBEngExt, Fmx.Bind.Grid, System.Bindings.Outputs,
Fmx.Bind.Editors, Data.Bind.Components, Data.Bind.Grid, Data.Bind.DBScope,
IPPeerClient, Data.DBXDataSnap, Data.DBXCommon, FMX.Grid.Style, FMX.ScrollBox,
FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error,
FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, FireDAC.Stan.StorageJSON, FireDAC.Stan.StorageXML,
FireDAC.Stan.StorageBin, Data.FireDACJSONReflect;
type
TForm1 = class(TForm)
SQLConnection1: TSQLConnection;
GroupBox1: TGroupBox;
Label1: TLabel;
edtIP: TEdit;
Label2: TLabel;
edtPort: TEdit;
btnConnect: TButton;
StringGrid1: TStringGrid;
btnQuery: TButton;
btnSave: TButton;
FDMemTable1: TFDMemTable;
FDMemTable1c1: TStringField;
FDMemTable1c2: TStringField;
BindSourceDB1: TBindSourceDB;
BindingsList1: TBindingsList;
LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource;
btnStoredProcedure: TButton;
procedure FormDestroy(Sender: TObject);
procedure btnConnectClick(Sender: TObject);
procedure btnQueryClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnStoredProcedureClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{$R *.LgXhdpiPh.fmx ANDROID}
uses
Unit3;
var
svrMethods: TServerMethods1Client;
procedure TForm1.btnConnectClick(Sender: TObject);
begin
with SQLConnection1 do
begin
Params.Values[‘HostName‘] := edtIP.Text;
Params.Values[‘Port‘] := edtPort.Text;
Connected := True;
end;
if SQLConnection1.Connected then
svrMethods := TServerMethods1Client.Create(SQLConnection1.DBXConnection)
else
ShowMessage(‘连接中间件失败‘);
end;
procedure TForm1.btnQueryClick(Sender: TObject);
var
LDataSets: TFDJSONDataSets;
LDataSet: TFDDataSet;
begin
LDataSets := svrMethods.QuerySql2(‘0‘, ‘select * from t1‘);
LDataSet := TFDJSONDataSetsReader.GetListValueByName(LDataSets, ‘1‘);
FDMemTable1.Close;
FDMemTable1.Data := LDataSet;
end;
procedure TForm1.btnSaveClick(Sender: TObject);
var
LDeltas: TFDJSONDeltas;
begin
if FDMemTable1.State in dsEditModes then
FDMemTable1.Post
else
Exit;
LDeltas := TFDJSONDeltas.Create;
TFDJSONDeltasWriter.ListAdd(LDeltas, ‘1‘, FDMemTable1);
if svrMethods.SaveData2(‘0‘, ‘t1‘, LDeltas) then
ShowMessage(‘save ok‘)
else
ShowMessage(‘save fail‘);
end;
procedure TForm1.btnStoredProcedureClick(Sender: TObject);
var
LDataSets: TFDJSONDataSets;
LDataSet: TFDDataSet;
begin
LDataSets := svrMethods.spOpen2(‘0‘, ‘sp_test‘, ‘@c1:11‘);
LDataSet := TFDJSONDataSetsReader.GetListValueByName(LDataSets, ‘1‘);
FDMemTable1.Close;
FDMemTable1.Data := LDataSet;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDMemTable1.CachedUpdates := True;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
svrMethods.Free;
end;
end.
FDMemTable的详细使用方法