150 |
|
FGrid: TCustomGrid; |
151 |
|
FCol,FRow: Integer; |
152 |
|
FEditText: string; |
153 |
+ |
function EditingKeyField: boolean; |
154 |
|
protected |
155 |
|
procedure WndProc(var TheMessage : TLMessage); override; |
156 |
|
procedure CloseUp; override; |
260 |
|
FBookmark: TLocationArray; |
261 |
|
FDBLookupCellEditor: TDBLookupCellEditor; |
262 |
|
FActive: boolean; |
263 |
+ |
FFieldPosition: integer; |
264 |
|
procedure ColumnHeaderClick(Index: integer); |
265 |
|
function GetDataSource: TDataSource; |
266 |
|
function GetEditorBorderStyle: TBorderStyle; |
306 |
|
|
307 |
|
implementation |
308 |
|
|
309 |
< |
uses Math, IBQuery, LCLType; |
309 |
> |
uses Math, IBQuery, LCLType, Variants; |
310 |
|
|
311 |
|
{ TIBGridControlLink } |
312 |
|
|
372 |
|
else |
373 |
|
begin |
374 |
|
for I := 0 to ColCount - 1 do |
375 |
+ |
if (I < FixedCols) or Columns[I - FixedCols].Visible then |
376 |
|
ColSum := ColSum + ColWidths[I]; |
377 |
|
|
378 |
|
if Colsum <> ClientWidth then |
379 |
|
begin |
380 |
|
ResizeColCount := 0; |
381 |
|
for I := 0 to Columns.Count -1 do |
382 |
< |
if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn then |
382 |
> |
if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn and Columns[I].Visible then |
383 |
|
begin |
384 |
|
Inc(ResizeColCount); |
385 |
|
Colsum := Colsum + TDBDynamicGridColumn(Columns[I]).DesignWidth - Columns[I].Width; |
392 |
|
n := (ClientWidth - ColSum) mod ResizeColCount; |
393 |
|
|
394 |
|
for I := 0 to Columns.Count -1 do |
395 |
< |
if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn then |
395 |
> |
if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn and Columns[I].Visible then |
396 |
|
begin |
397 |
|
if I = 0 then |
398 |
|
Columns[I].Width := Columns[I].Width + adjustment + n |
611 |
|
if FEditorPanel <> nil then |
612 |
|
RemoveFreeNotification(FEditorPanel); |
613 |
|
FEditorPanel := AValue; |
614 |
< |
FreeNotification(FEditorPanel); |
614 |
> |
if FEditorPanel <> nil then |
615 |
> |
FreeNotification(FEditorPanel); |
616 |
|
end; |
617 |
|
|
618 |
|
procedure TDBDynamicGrid.ChangeBounds(ALeft, ATop, AWidth, AHeight: integer; |
679 |
|
|
680 |
|
procedure TDBDynamicGrid.Notification(AComponent: TComponent; |
681 |
|
Operation: TOperation); |
682 |
+ |
var i: integer; |
683 |
|
begin |
684 |
|
inherited Notification(AComponent, Operation); |
685 |
< |
if (Operation = opRemove) and |
686 |
< |
(AComponent = FEditorPanel) then FEditorPanel := nil; |
685 |
> |
if (Operation = opRemove) and not (csDestroying in ComponentState) then |
686 |
> |
begin |
687 |
> |
if AComponent = FEditorPanel then |
688 |
> |
FEditorPanel := nil |
689 |
> |
else |
690 |
> |
if AComponent is TControl then |
691 |
> |
begin |
692 |
> |
for i := 0 to Columns.Count - 1 do |
693 |
> |
if TDBDynamicGridColumn(Columns[I]).ColumnTotalsControl = AComponent then |
694 |
> |
TDBDynamicGridColumn(Columns[I]).ColumnTotalsControl := nil; |
695 |
> |
end; |
696 |
> |
end |
697 |
|
end; |
698 |
|
|
699 |
|
procedure TDBDynamicGrid.TopLeftChanged; |
788 |
|
Result := inherited Width |
789 |
|
end; |
790 |
|
|
791 |
+ |
type |
792 |
+ |
THackedGrid = class(TIBDynamicGrid) |
793 |
+ |
public |
794 |
+ |
property FixedCols; |
795 |
+ |
end; |
796 |
+ |
|
797 |
|
{ TDBLookupCellEditor } |
798 |
|
|
799 |
+ |
function TDBLookupCellEditor.EditingKeyField: boolean; |
800 |
+ |
begin |
801 |
+ |
with TIBDynamicGridColumn(TDBGrid(FGrid).Columns[FCol - THackedGrid(FGrid).FixedCols]) do |
802 |
+ |
Result := CompareText(FieldName, DBLookupProperties.DataFieldName) = 0; |
803 |
+ |
end; |
804 |
+ |
|
805 |
|
procedure TDBLookupCellEditor.WndProc(var TheMessage: TLMessage); |
806 |
|
begin |
807 |
|
if TheMessage.msg=LM_KILLFOCUS then begin |
820 |
|
UpdateData(nil); {Force Record Update} |
821 |
|
if FGrid<>nil then |
822 |
|
Begin |
823 |
< |
(FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, Trim(Text)); |
823 |
> |
if EditingKeyField then |
824 |
> |
begin |
825 |
> |
if not VarIsNull(KeyValue) then |
826 |
> |
(FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, KeyValue) |
827 |
> |
end |
828 |
> |
else |
829 |
> |
(FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, Trim(Text)); |
830 |
|
(FGrid as TIBDynamicGrid).UpdateData; |
831 |
|
end; |
832 |
|
inherited CloseUp; |
851 |
|
CheckAndInsert; |
852 |
|
Msg.Col := FCol; |
853 |
|
Msg.Row := FRow; |
854 |
< |
Msg.Value:= Trim(Text); |
854 |
> |
if EditingKeyField then |
855 |
> |
begin |
856 |
> |
if not VarIsNull(KeyValue) then |
857 |
> |
Msg.Value:= KeyValue |
858 |
> |
else |
859 |
> |
Msg.Value:= '' |
860 |
> |
end |
861 |
> |
else |
862 |
> |
Msg.Value:= Trim(Text); |
863 |
|
end; |
864 |
|
|
865 |
|
procedure TDBLookupCellEditor.msg_SetGrid(var Msg: TGridMessage); |
947 |
|
if DataFieldName <> '' then |
948 |
|
Editor.DataSource := TDBGrid(Grid).DataSource; |
949 |
|
end; |
950 |
< |
Editor.Text := Editor.FEditText; |
950 |
> |
if Editor.EditingKeyField then |
951 |
> |
begin |
952 |
> |
if not Field.IsNull then |
953 |
> |
Editor.KeyValue := Editor.FEditText |
954 |
> |
end |
955 |
> |
else |
956 |
> |
Editor.Text := Editor.FEditText; |
957 |
|
Editor.SelStart := Length(Editor.Text); |
958 |
|
end; |
959 |
|
|
995 |
|
OnColumnHeaderClick(self,Index); |
996 |
|
|
997 |
|
FLastColIndex := Index; |
998 |
< |
if assigned(DataSource) and assigned(DataSource.DataSet) and DataSource.DataSet.Active then |
998 |
> |
FFieldPosition := 0; |
999 |
> |
if assigned(DataSource) and assigned(DataSource.DataSet) and DataSource.DataSet.Active |
1000 |
> |
and (DataSource.DataSet is TIBParserDataSet) then |
1001 |
|
begin |
1002 |
+ |
if FLastColIndex < Columns.Count then |
1003 |
+ |
{try and cache field position while dataset still open} |
1004 |
+ |
FFieldPosition := TIBParserDataSet(DataSource.DataSet).Parser.GetFieldPosition(Columns[FLastColIndex].FieldName); |
1005 |
|
DataSource.DataSet.Active := false; |
1006 |
|
Application.QueueAsyncCall(@DoReopen,0) |
1007 |
|
end; |
1049 |
|
for i := 0 to Columns.Count - 1 do |
1050 |
|
begin |
1051 |
|
if TIBDynamicGridColumn(columns[i]).InitialSortColumn then |
1052 |
+ |
begin |
1053 |
+ |
FFieldPosition := 0; |
1054 |
|
FLastColIndex := i |
1055 |
+ |
end |
1056 |
|
end |
1057 |
|
end; |
1058 |
|
|
1069 |
|
|
1070 |
|
procedure TIBDynamicGrid.UpdateSQL(Sender: TObject; Parser: TSelectSQLParser); |
1071 |
|
var OrderBy: string; |
1017 |
– |
FieldPosition: integer; |
1072 |
|
begin |
1073 |
|
if assigned(DataSource) and assigned(DataSource.DataSet) |
1074 |
|
and (DataSource.DataSet is TIBCustomDataSet) then |
1075 |
|
begin |
1076 |
< |
if (FLastColIndex < 0) or (FLastColIndex >= Columns.Count) then Exit; |
1077 |
< |
FieldPosition := Parser.GetFieldPosition(Columns[FLastColIndex].FieldName); |
1078 |
< |
if FieldPosition > 0 then |
1076 |
> |
if (FFieldPosition = 0) and (FLastColIndex >= 0) and (FLastColIndex < Columns.Count) then |
1077 |
> |
{Not cached - let's hope we can find it before the dataset is opened. |
1078 |
> |
Won't work if dynamic columns} |
1079 |
> |
FFieldPosition := Parser.GetFieldPosition(Columns[FLastColIndex].FieldName); |
1080 |
> |
if FFieldPosition > 0 then |
1081 |
|
begin |
1082 |
|
if Descending then |
1083 |
< |
Parser.OrderByClause := IntToStr(FieldPosition) + ' desc' |
1083 |
> |
Parser.OrderByClause := IntToStr(FFieldPosition) + ' desc' |
1084 |
|
else |
1085 |
< |
Parser.OrderByClause := IntToStr(FieldPosition) + ' asc'; |
1085 |
> |
Parser.OrderByClause := IntToStr(FFieldPosition) + ' asc'; |
1086 |
|
end; |
1087 |
|
|
1088 |
|
if assigned(FOnUpdateSortOrder) then |
1226 |
|
|
1227 |
|
procedure TIBDynamicGrid.Notification(AComponent: TComponent; |
1228 |
|
Operation: TOperation); |
1229 |
+ |
var i: integer; |
1230 |
|
begin |
1231 |
|
inherited Notification(AComponent, Operation); |
1232 |
< |
if (Operation = opRemove) and |
1233 |
< |
(FIBControlLink <> nil) and (AComponent = DataSource) then FIBControlLink.IBDataSet := nil; |
1232 |
> |
if (Operation = opRemove) then |
1233 |
> |
begin |
1234 |
> |
if (FIBControlLink <> nil) and (AComponent = DataSource) then |
1235 |
> |
FIBControlLink.IBDataSet := nil |
1236 |
> |
else |
1237 |
> |
if AComponent is TDataSource then |
1238 |
> |
begin |
1239 |
> |
for i := 0 to Columns.Count - 1 do |
1240 |
> |
if TIBDynamicGridColumn(Columns[I]).DBLookupProperties.ListSource = AComponent then |
1241 |
> |
TIBDynamicGridColumn(Columns[I]).DBLookupProperties.ListSource := nil; |
1242 |
> |
end |
1243 |
> |
end |
1244 |
|
end; |
1245 |
|
|
1246 |
|
procedure TIBDynamicGrid.UpdateActive; |