通用Delphi数据库输入控件DBPanel的实现(5) (DS: TDataSource; ColCount: Integer);var i, n, RowCount: Integer; TextHeight: Integer;begin if DataSource.DataSet.Active then begin n := DataSource.DataSet.FieldCount; { 计算最大的标题长度及显示长度} DataSource.DataSet.First; { 计算高度} TextHeight := Canvas.TextHeight(DataSource .DataSet.Fields[0].DisplayLabel) + FLineHeight; //10; { 计算行列数} RowCount := n div Columns; if n mod Columns < > 0 then inc(RowCount); { 分配内存} FreeEditors; SetLength(Editors, n); SetLength(Labels, n); { 创建滚动盒} FScrollBox := TScrollBox.Create(Owner); FScrollBox.Parent := Self; FScrollBox.Align := alClient; { 创建编辑} for i:=0 to n-1 do begin { 创建标题} Labels[i] := TLabel.Create(Owner); Labels[i].Parent := FScrollBox; //Self;Labels[i].Caption := DataSource.DataSet.Fields[i].DisplayLabel; Labels[i].Left := FLeft + (maxLabelLen + maxTextLen + 10) * (i div RowCount); Labels[i].Width := maxLabelLen;Labels[i].Top := FTop + (i mod RowCount) * TextHeight + 5; { 创建编辑对象} Editors[i] := TDBComboBox.Create(Owner); Editors[i].Parent := FScrollBox; //Self; Editors[i].Left := Labels[i].Left + Labels[i].Width; Editors[i].Width := maxTextLen; Editors[i].Top := FTop + (i mod RowCount) * TextHeight; Editors[i].DataSource := DataSource; Editors[i].DataField := DataSource.DataSet.Fields[i].FieldName; Editors[i].OnKeyPress := AKeyPress;