ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/ibcontrols/IBDynamicGrid.pas
(Generate patch)

Comparing ibx/trunk/ibcontrols/IBDynamicGrid.pas (file contents):
Revision 37 by tony, Mon Feb 15 14:44:25 2016 UTC vs.
Revision 39 by tony, Tue May 17 08:14:52 2016 UTC

# Line 150 | Line 150 | end;
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;
# Line 305 | Line 306 | end;
306  
307   implementation
308  
309 < uses Math, IBQuery, LCLType;
309 > uses Math, IBQuery, LCLType, Variants;
310  
311   { TIBGridControlLink }
312  
# Line 371 | Line 372 | begin
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;
# Line 390 | Line 392 | begin
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
# Line 609 | Line 611 | begin
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;
# Line 676 | Line 679 | end;
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;
# Line 774 | Line 788 | begin
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
# Line 794 | Line 820 | 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;
# Line 819 | Line 851 | begin
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);
# Line 907 | Line 947 | begin
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  
# Line 1180 | Line 1226 | end;
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines