IdeIntf, DBGridColumnsPropertyEditorForm: Simplify actAddFieldsExecute a lot, new method GetDataSet. Issue #32903, patch from FTurtle.

git-svn-id: trunk@57061 -
This commit is contained in:
juha 2018-01-12 16:39:18 +00:00
parent 8e09be3eed
commit 61e0c2a1ff

View File

@ -52,6 +52,7 @@ type
FOwnerPersistent: TPersistent; FOwnerPersistent: TPersistent;
FPropertyName: String; FPropertyName: String;
procedure FillCollectionListBox; procedure FillCollectionListBox;
function GetDataSet: TDataSet;
procedure SelectInObjectInspector; procedure SelectInObjectInspector;
procedure UnSelectInObjectInspector; procedure UnSelectInObjectInspector;
procedure UpdDesignHook(aSelection: TPersistentSelectionList); procedure UpdDesignHook(aSelection: TPersistentSelectionList);
@ -135,55 +136,34 @@ end;
procedure TDBGridColumnsPropertyEditorForm.actAddFieldsExecute(Sender: TObject); procedure TDBGridColumnsPropertyEditorForm.actAddFieldsExecute(Sender: TObject);
var var
It : TCollectionItem; DataSet: TDataSet;
flChanged : Boolean; Item: TColumn;
flEmpty : Boolean;
i: Integer; i: Integer;
begin begin
if Collection=nil then Exit; if Collection=nil then Exit;
if not (Collection is TDBGridColumns) then Exit; if not (Collection is TDBGridColumns) then Exit;
DataSet:=GetDataSet;
if DataSet=nil then Exit;
flChanged := False;
flEmpty := False;
if Collection.Count>0 then if Collection.Count>0 then
It := Collection.Items[ 0 ] if (MessageDlg(dceColumnEditor, dceOkToDelete, mtConfirmation, [mbYes, mbNo], 0) <> mrYes) then
else begin Exit;
It := Collection.Add;
flEmpty:=True;
end;
if flEmpty or (MessageDlg(dceColumnEditor, dceOkToDelete, mtConfirmation,
[mbYes, mbNo], 0) = mrYes) then
try try
if (It is TColumn) and ( Assigned( TDBGrid( TColumn( It ).Grid).DataSource ) )
and Assigned ( TDBGrid( TColumn( It ).Grid).DataSource.DataSet ) then
begin
flChanged:=True;
Collection.Clear; Collection.Clear;
It := Collection.Add; for i:=0 to DataSet.Fields.Count-1 do
if TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count > 0 then
begin begin
for i := 0 to TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count - 1 do Item:=Collection.Add as TColumn;
begin Item.Field:=DataSet.Fields[i];
if i > 0 then Item.Title.Caption:=DataSet.Fields[i].DisplayLabel;
It := Collection.Add;
TColumn( It ).Field:=TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields[ i ];
TColumn( It ).Title.Caption:=TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields[ i ].DisplayLabel;
end;
end;
end; end;
finally finally
if flChanged or flEmpty then
begin
if not flChanged then
Collection.Clear;
RefreshPropertyValues; RefreshPropertyValues;
UpdateButtons; UpdateButtons;
UpdateCaption; UpdateCaption;
Modified; Modified;
end; end;
end; end;
end;
procedure TDBGridColumnsPropertyEditorForm.actDeleteAllExecute(Sender: TObject); procedure TDBGridColumnsPropertyEditorForm.actDeleteAllExecute(Sender: TObject);
begin begin
@ -242,8 +222,7 @@ var
Field: TField; Field: TField;
i: Integer; i: Integer;
begin begin
if (FOwnerPersistent as TDBGrid).DataSource=nil then Exit; DataSet:=GetDataSet;
DataSet:=TDBGrid(FOwnerPersistent).DataSource.DataSet;
if DataSet=nil then Exit; if DataSet=nil then Exit;
if MessageDlg(dceColumnEditor, dceWillReplaceContinue, mtConfirmation, if MessageDlg(dceColumnEditor, dceWillReplaceContinue, mtConfirmation,
@ -397,6 +376,12 @@ begin
end; end;
end; end;
function TDBGridColumnsPropertyEditorForm.GetDataSet: TDataSet;
begin
if (FOwnerPersistent as TDBGrid).DataSource=nil then Exit(nil);
Result:=TDBGrid(FOwnerPersistent).DataSource.DataSet;
end;
procedure TDBGridColumnsPropertyEditorForm.SelectInObjectInspector; procedure TDBGridColumnsPropertyEditorForm.SelectInObjectInspector;
var var
I: Integer; I: Integer;