📄 dynamicdatasetunit.pas
字号:
unit DynamicDataSetUnit;
interface
uses
Windows, Classes, SysUtils, DB, DBClient, Variants;
type
TDynamicDataSet = Class(TPersistent)
private
//打包传给客户端的相关TDataSet信息.
published
procedure prepareTable(tmpDS: TDataSet); virtual;
procedure InitOleFields(tmpDS: TDataSet);
procedure CreateDataSet(tmpDS: TDataSet); virtual;
public
OleFields: OleVariant;
OleFldName: OleVariant;
OleFldType: OleVariant;
OleFldSize: OleVariant;
DataSet: TClientDataSet;
constructor Create; virtual;
end;
implementation
constructor TDynamicDataSet.Create;
begin
inherited Create;
DataSet := TClientDataSet.Create(nil);
OleFields := VarArrayCreate([0,2], varVariant);
end;
procedure TDynamicDataSet.InitOleFields(tmpDS: TDataSet);
var
i_i: Integer;
begin
OleFldName := VarArrayCreate([0,tmpDS.FieldCount-1],varVariant);
OleFldType := VarArrayCreate([0,tmpDS.FieldCount-1],varVariant);
OleFldSize := VarArrayCreate([0,tmpDS.FieldCount-1],varVariant);
for i_i:=0 to tmpDS.FieldCount-1 do
begin
OleFldName[i_i] := tmpDS.Fields[i_i].FieldName;
OleFldType[i_i] := tmpDS.Fields[i_i].DataType;
OleFldSize[i_i] := tmpDS.Fields[i_i].Size;
end;
OleFields[0] := OleFldName;
OleFields[1] := OleFldType;
OleFields[2] := OleFldSize;
end;
procedure TDynamicDataSet.CreateDataSet(tmpDS: TDataSet);
var
i_i: integer;
begin
DataSet.FieldDefs.Clear;
DataSet.Close;
for i_i:=0 to tmpDS.FieldCount-1 do
begin
with DataSet.FieldDefs.AddFieldDef do
begin
Name := tmpDS.Fields[i_i].FieldName;
DataType := tmpDS.Fields[i_i].DataType;
Size := tmpDS.Fields[i_i].Size;
end;
end;
DataSet.CreateDataSet;
DataSet.Open;
end;
procedure TDynamicDataSet.prepareTable(tmpDS: TDataSet);
begin
//赋值:
InitOleFields(tmpDS);
CreateDataSet(tmpDS);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -