View Issue Details

IDProjectCategoryView StatusLast Update
0001778JEDI VCL00 JVCL Componentspublic2004-09-03 14:37
ReporteryuriAssigned ToAHUser 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0001778: JvDBGrid bug in KeyPress procedure with lookup fields
DescriptionBUG1:I use a lookup field and type in a column of the lookup field some text. I receive an error "Operation not applicable" if the length of the text in a cell is equal to the size of the field and I press one more key.
It happened in KeyPress procedure of TJvDBGrid in the follow line "if LookupDataSet.Locate(LookupResultField, lWord, [loCaseInsensitive, loPartialKey]) then"
The locate does not accept the length of the search text more than the size of the field of the search (the length of lWord must be less or equal to the size of the field).

BUG2: Also there is no check whether the column is ReadOnly (need to check Columns[SelectedIndex].ReadOnly and do not change the field value if Columns[SelectedIndex].ReadOnly=True).

BUG3: And it will be useful if we can change the set of char declared in cChar const (in KeyPress procedure), because it does not contain all available characters for string field and as a result the selection of the the value "when the user types the first characters of a word found in the list" work only for english set of chars.
Additional InformationI correct the code to solve the described bugs (see upload file).
TagsNo tags attached.

Activities

2004-05-17 05:31

 

upload1.txt (4,090 bytes)
Changes in TJvDBGrid

  TJvDBGrid = class(TJvExDBGrid)
  private
..
  protected
..
    procedure InternalKeyPress(var Key: Char; AChar: TFieldChars); virtual;
    function SelectCell(ACol, ARow: Integer): overload;
  public
..
  end;


procedure TJvDBGrid.KeyPress(var Key: Char);
const
  cChar = ['A'..'Z', 'a'..'z', ' ', '-', '+', '0'..'9', '.', ',',
    '�', '�', '�', '�', '�', '�', '�', '�', '�', '�', '�', '�', #8];
begin
  // Remark: InplaceEditor is protected in TCustomGrid, published in TJvDBGrid
  // Goal: Allow to go directly into the InplaceEditor when one types the first
  // characters of a word found in the list.
  if not ReadOnly then
    if (Key = #13) and FPostOnEnter then
      DataSource.DataSet.CheckBrowseMode
    else
      if not(Columns[SelectedIndex].ReadOnly) then
        InternalKeyPress(Key,cChar);

  if EditorMode then
    inherited OnKeyPress := FOnKeyPress;
  try
    inherited KeyPress(Key);
  finally
    inherited OnKeyPress := nil;
  end;
end;

procedure TJvDBGrid.InternalKeyPress(var Key: Char; AChar: TFieldChars);
var
  lWord: string;
  lMasterField: TField;
  I, deb: Integer;
begin
  with Columns[SelectedIndex].Field do
    if FieldKind = fkLookup then
    begin
      if (Key in AChar) then
      begin
        if Pos(AnsiUpperCase(FWord), AnsiUpperCase(InplaceEditor.EditText)) <> 1 then
          FWord := '';
        if Key = #8 then
          if (FWord = '') or (Length(FWord) = 1) then
          begin
            lWord := '';
            FWord := '';
          end
          else
            lWord := Copy(FWord, 1, Length(FWord) - 1)
        else
          lWord := FWord + Key;

        LookupDataSet.DisableControls;
        try
          try
            if LookupDataSet.Locate(LookupResultField, lWord, [loCaseInsensitive, loPartialKey]) then
            begin
              DataSet.Edit;
              lMasterField := DataSet.FieldByName(KeyFields);
              if lMasterField.CanModify then
              begin
                lMasterField.Value := LookupDataSet.FieldValues[LookupKeyFields];
                FWord := lWord;
                InplaceEditor.SelStart := Length(FWord);
                InplaceEditor.SelLength := Length(InplaceEditor.EditText) - Length(FWord);
              end;
            end;
          except
            { If you attempt to search for a string larger than what the field
              can hold, and exception will be raised.  Just trap it }
          end;
        finally
          LookupDataSet.EnableControls;
        end;
      end;
    end
    else if FieldKind = fkData then
    begin
      if DataType = ftFloat then
        if Key in ['.', ','] then
          Key := DecimalSeparator;

      if (Key in AChar) and (Columns[SelectedIndex].PickList.Count <> 0) then
      begin
        if Pos(AnsiUpperCase(FWord), AnsiUpperCase(InplaceEditor.EditText)) <> 1 then
          FWord := '';
        if Key = #8 then
          if (FWord = '') or (Length(FWord) = 1) then
          begin
            lWord := '';
            FWord := '';
          end
          else
            lWord := Copy(FWord, 1, Length(FWord) - 1)
        else
          lWord := FWord + Key;

        Key := #0; // De toute fa�on le caract�re est supprim�
        with Columns[SelectedIndex].PickList do
          for I := 0 to Count - 1 do
          begin
            deb := Length(lWord);
            if AnsiUpperCase(lWord) = AnsiUpperCase(Copy(Strings[I], 1, deb)) then
            begin
              DataSet.Edit;

              InplaceEditor.EditText := Strings[I];
              Columns[SelectedIndex].Field.Text := Strings[I];
              InplaceEditor.SelStart := deb;
              InplaceEditor.SelLength := Length(Text) - deb;
              FWord := lWord;

              Break;
            end;
          end;
      end;
    end;
end;

function TJvDBGrid.SelectCell(ACol, ARow: Integer): Boolean;
begin
  FWord:='';
  Result:=inherited SelectCell(ACol, ARow);
end;
upload1.txt (4,090 bytes)

user72

2004-05-24 00:29

  ~0004331

JvDBGrid will probably be merged with recently donated UltimDbGrid soon, so I don't think we will see any fixes before that

obones

2004-08-05 23:08

administrator   ~0004940

Last edited: 2004-08-05 23:09

Bug 1 could not be reproduced, could you give us more details, after having tried with the latest code.

Bug 2 and 3 are now fixed in CVS

To get the latest code, use the daily zip packages of both the JCL and JVCL:

http://jvcl.sf.net/daily/
http://jcl.sf.net/daily/

edited on: 08-05-04 23:09

user72

2004-08-05 23:16

  ~0004944

BUG1: this sounds more like a problem with the dataset. What type of dataset are you using?

2004-08-16 00:17

 

test.exe (387,195 bytes)

anonymous

2004-08-16 00:31

viewer   ~0004998

I uploaded an example test.exe with BUG1. This archive contains the example project and the img1.bmp file with the description how to see the error. In my upload1.txt I suggest trap this bug with "try ... except end"
=====start
...
         try
            if LookupDataSet.Locate(LookupResultField, lWord, [loCaseInsensitive, loPartialKey]) then
            begin
              DataSet.Edit;
              lMasterField := DataSet.FieldByName(KeyFields);
              if lMasterField.CanModify then
              begin
                lMasterField.Value := LookupDataSet.FieldValues[LookupKeyFields];
                FWord := lWord;
                InplaceEditor.SelStart := Length(FWord);
                InplaceEditor.SelLength := Length(InplaceEditor.EditText) - Length(FWord);
              end;
            end;
          except
            { If you attempt to search for a string larger than what the field
              can hold, and exception will be raised. Just trap it }
          end;
...
====end

In TDBLookupControl.ProcessSearchKey Borland solve the problem with the same way

yuri

2004-08-16 00:55

reporter   ~0004999

Also, it would be better to change UpperCase to AnsiUpperCase in CharsToFind procedure;

    if Pos(UpperCase(FWord), UpperCase(InplaceEditor.EditText)) <> 1 then
change to
    if Pos(AnsiUpperCase(FWord), AnsiUpperCase(InplaceEditor.EditText))<>1 then
           ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

AHUser

2004-09-03 14:37

developer   ~0005168

Bug 1, 2 and 3 are now fixed.

Issue History

Date Modified Username Field Change
2004-05-17 05:31 yuri New Issue
2004-05-17 05:31 yuri File Added: upload1.txt
2004-05-24 00:29 user72 Note Added: 0004331
2004-05-24 01:18 user72 Status new => acknowledged
2004-08-05 23:08 obones Note Added: 0004940
2004-08-05 23:08 obones Status acknowledged => feedback
2004-08-05 23:09 obones Note Edited: 0004940
2004-08-05 23:16 user72 Note Added: 0004944
2004-08-16 00:17 anonymous File Added: test.exe
2004-08-16 00:31 anonymous Note Added: 0004998
2004-08-16 00:55 yuri Note Added: 0004999
2004-09-03 14:37 AHUser Status feedback => resolved
2004-09-03 14:37 AHUser Resolution open => fixed
2004-09-03 14:37 AHUser Assigned To => AHUser
2004-09-03 14:37 AHUser Note Added: 0005168