起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 203|回复: 4

【结贴】[请求]代码什么意思**

[复制链接]
发表于 2009-5-9 16:49:00 | 显示全部楼层 |阅读模式
constructor TQXJLXX.Create(AContext: TContext);
begin
  inherited Create(AContext);
  FData := TSheetDataSetContainer.Create();
  FData.FDataSets := [DataSetGDJCXX,DataSetGDFJWDB,DataSetKSGSJB,
                                          DataSetGDAQCSB,DataSetGDFZRGHB,DataSetGZCYGHB,DataSetYJMX];
  
end;

请问红色部分是构造一个数据集吗?是将几个数据集合起来还是怎么?谢谢
回复

使用道具 举报

发表于 2009-5-11 09:11:52 | 显示全部楼层
楼主,请看以下TSheetDataSetContainer这个对象的具体信息
看着像是一个数据集的容器。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-5-11 09:39:54 | 显示全部楼层
TSheetDataSetContainer = class
  private
    function GetConnection: TConnection;
    function GetMaster: TSQLDataSet;
    function GetDataSetCount: Integer;
    function GetDataSet(Index: Integer): TSQLDataSet;
  public
    FDataSets: array of TSQLDataSet;
    procedure UpdateRecords;
    function ConfirmUpdates: Boolean;
    function UpdatesPending: Boolean;
    procedure ApplyUpdates;
    procedure CancelUpdates;
    procedure DisableControls;
    procedure EnableControls;
    property Connection: TConnection read GetConnection;
    property Master: TSQLDataSet read GetMaster;

    property DataSets[Index: Integer]: TSQLDataSet read GetDataSet;
    property DataSetCount: Integer read GetDataSetCount;
  end;

function TSheetDataSetContainer.GetConnection: TConnection;
begin
  Result := Master.Connection;
end;

function TSheetDataSetContainer.GetMaster: TSQLDataSet;
begin
  Result := DataSets[0];
end;

function TSheetDataSetContainer.GetDataSetCount: Integer;
begin
  if FDataSets = nil then
    Result := 0
  else
    Result := Length(FDataSets);
end;

function TSheetDataSetContainer.GetDataSet(Index: Integer): TSQLDataSet;
begin
  Result := FDataSets[Index];
end;

procedure TSheetDataSetContainer.UpdateRecords;
var
  I: Integer;
begin
  for I := 0 to DataSetCount - 1 do
  begin
    if (DataSets[I] <> nil) and
      (DataSets[I].State in [TDataSetState.dsEdit, TDataSetState.dsInsert]) and
      DataSets[I].Modified then
      begin
        DataSets[I].UpdateRecord;
        DataSets[I].Post;
      end;
  end;
end;

function TSheetDataSetContainer.ConfirmUpdates: Boolean;
begin
  Result := True;

  if UpdatesPending then
    case JSDialogs.QuestionBox('数据已经被修改,是否保存?', Forms.Application.Title, 1) of
      Borland.Delphi.Windows.IDYES:
        ApplyUpdates;
      Borland.Delphi.Windows.IDNO:
        CancelUpdates;
    else
      Result := False;
    end;
end;

function TSheetDataSetContainer.UpdatesPending: boolean;
var
  I: Integer;
begin
  for I := 0 to DataSetCount - 1 do
    if (DataSets[I] <> nil) and
      DataSets[I].UpdatesPending and
      DataSets[I].UpdateOptions.Enabled then
    begin
      Result := not Master.IsEmpty;
      Exit;
    end;

  Result := False;
end;

procedure TSheetDataSetContainer.ApplyUpdates;
var
  I: Integer;
begin
  for I := 0 to DataSetCount - 1 do
  begin
    try
    if (DataSets[I] <> nil) and
      DataSets[I].UpdatesPending and
      DataSets[I].UpdateOptions.Enabled {and
      not DataSets[I].Relation.Active }then
      DataSets[I].ApplyUpdates(False);
    except
      continue;
    end;
  end;
end;

procedure TSheetDataSetContainer.CancelUpdates;
var
  I: Integer;
begin
  for I := 0 to DataSetCount - 1 do
  begin
    if DataSets[I] = nil then
      Continue;

    if DataSets[I].State in [TDataSetState.dsInsert, TDataSetState.dsEdit] then
      DataSets[I].Cancel;
    if DataSets[I].UpdatesPending then
      DataSets[I].CancelUpdates;
  end;
end;

procedure TSheetDataSetContainer.DisableControls;
var
  I: Integer;
begin
  for I := 0 to DataSetCount - 1 do
    if DataSets[I] <> nil then
      DataSets[I].DisableControls;
end;

procedure TSheetDataSetContainer.EnableControls;
var
  I: Integer;
begin
  for I := 0 to DataSetCount - 1 do
    if DataSets[I] <> nil then
      DataSets[I].EnableControls;
end;
回复 支持 反对

使用道具 举报

发表于 2009-5-11 09:51:35 | 显示全部楼层
看这个类的定义
FDataSets: array of TSQLDataSet;

FDataSets是一个标准数据集的数组
那么1楼的代码就是给这个数组赋值。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-5-11 10:11:33 | 显示全部楼层
谢谢斑竹,结贴。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-21 16:57 , Processed in 0.044537 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表