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,54 +136,33 @@ 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; if Collection.Count>0 then
flEmpty := False; if (MessageDlg(dceColumnEditor, dceOkToDelete, mtConfirmation, [mbYes, mbNo], 0) <> mrYes) then
if Collection.Count > 0 then Exit;
It := Collection.Items[ 0 ]
else begin
It := Collection.Add;
flEmpty:=True;
end;
if flEmpty or (MessageDlg(dceColumnEditor, dceOkToDelete, mtConfirmation, try
[mbYes, mbNo], 0) = mrYes) then Collection.Clear;
try for i:=0 to DataSet.Fields.Count-1 do
if (It is TColumn) and ( Assigned( TDBGrid( TColumn( It ).Grid).DataSource ) ) begin
and Assigned ( TDBGrid( TColumn( It ).Grid).DataSource.DataSet ) then Item:=Collection.Add as TColumn;
begin Item.Field:=DataSet.Fields[i];
flChanged:=True; Item.Title.Caption:=DataSet.Fields[i].DisplayLabel;
Collection.Clear;
It := Collection.Add;
if TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count > 0 then
begin
for i := 0 to TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count - 1 do
begin
if i > 0 then
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;
finally
if flChanged or flEmpty then
begin
if not flChanged then
Collection.Clear;
RefreshPropertyValues;
UpdateButtons;
UpdateCaption;
Modified;
end;
end; end;
finally
RefreshPropertyValues;
UpdateButtons;
UpdateCaption;
Modified;
end;
end; end;
procedure TDBGridColumnsPropertyEditorForm.actDeleteAllExecute(Sender: TObject); procedure TDBGridColumnsPropertyEditorForm.actDeleteAllExecute(Sender: TObject);
@ -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;