View Issue Details

IDProjectCategoryView StatusLast Update
0004826JEDI VCL00 JVCL Componentspublic2009-08-13 14:21
ReporterZENsanAssigned Toobones 
PrioritynormalSeverityblockReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.38 
Summary0004826: JvMemoryData when used as lookup source fails to locate key (TDBLookupComboBox) FIX provided
DescriptionJvMemoryData when used as lookup source fails to locate key (TDBLookupComboBox)

JvDBUtils.pas:
  function CompareField(var Field: TField; Value: Variant): Boolean; {BG}
  var
    S: string;
  begin
    if Field.DataType = ftString then
    ...
We need to change this to:

    if Field.DataType in [ftString, ftWideString] then

And also WHY JvDBUtils.pas uses AnsiSameStr, AnsiLowercase with string type everywhere, when we MUST use SameStr and Lowercase. (Just because it is wrong in Delphi 2009).
Additional InformationHope you will include this fix soon.
TagsNo tags attached.

Activities

ZENsan

2009-06-16 14:49

reporter   ~0015687

Forgot to say... It is in Delphi 2009 :)

ZENsan

2009-06-16 15:13

reporter   ~0015688

Also affected Filtering.. Every place where is staement = ftString, but not in [ftString, ftWideString]. affect delphi 2009..

ZENsan

2009-06-16 15:38

reporter   ~0015689

JvMemoryDataset.pas:
procedure TJvMemoryData.SetFiltered(Value: Boolean);
begin
  if Active then
  begin
    CheckBrowseMode;
    if Filtered <> Value then
    begin
      inherited SetFiltered(Value);
      First;
    end;
  end
  else
    inherited SetFiltered(Value);
end;

But MUST be (like in TBDETable) this way:

procedure TJvMemoryData.SetFiltered(Value: Boolean);
begin
  if Active then
  begin
    CheckBrowseMode;
    if Filtered <> Value then
      inherited SetFiltered(Value);
    First;
  end
  else
    inherited SetFiltered(Value);
end;

The original CodeGear code is:

procedure TBDEDataSet.SetFiltered(Value: Boolean);
begin
  if Active then
  begin
    CheckBrowseMode;
    if Filtered <> Value then
    begin
      DestroyLookupCursor;
      DbiSetToBegin(FHandle);
      if Value then ActivateFilters else DeactivateFilters;
      inherited SetFiltered(Value);
    end;
    First;
  end else
    inherited SetFiltered(Value);
end;

There you see that "First;" goes after "end;".

AHUser

2009-06-16 19:16

developer   ~0015691

Why is AnsiLowerCase wrong? For AnsiSameText/AnsiSameStr it is the missing SORT_STRINGSORT flag, but what's wrong with AnsiLowerCase?

ZENsan

2009-06-16 19:57

reporter   ~0015693

Maybe I am wrong.. As I remember AnsiSameStr get parameters AnsiString, not unicode string like field value can return in Delphi 2009.

AHUser

2009-06-16 20:11

developer   ~0015694

The "Ansi" prefix was kept for compatibility reasons in Delphi 2009. The functions accept "UnicodeString" instead of "AnsiString".

ZENsan

2009-06-17 08:04

reporter   ~0015698

The main problem that (1) Filtering and (2) Locate do not work with ftWideString, because this type is just not included in comparision as I described in Description.
(3) And Filter := True must refilter data (like in all TTable components which I know), but JvMemoryData do not do this because of - my comment above.

So 3 problems which are easy to fix.

ZENsan

2009-07-07 12:35

reporter   ~0015772

Still doesnt work with ftWideString...
Just need to add ftWideString in comparisions.

ZENsan

2009-07-07 12:36

reporter   ~0015773

at least for Delphi 2009...

obones

2009-07-09 13:41

administrator   ~0015803

So, where does it need to be added?

ZENsan

2009-07-17 17:02

reporter   ~0015861

JvDBUtils.pas:
  if Field.DataType = ftString then

These lines for D2009 must be
  if Field.DataType in [ftString, ftWideString] then

And also read 3rd comment

ZENsan

2009-07-17 17:02

reporter   ~0015862

If we upgrde that
  if Field.DataType = ftString then
for all version of delphi, then we need to handle there ftWideString separately

obones

2009-07-21 11:15

administrator   ~0015868

I would really appreciate a patch file in TortoiseSVN format against the latest sources

2009-07-22 14:06

 

JvMemoryDataset.diff (779 bytes)
--- D:/jvcl/run/JvMemoryDataset.pas	�� �� 22 14:29:30 2009
+++ C:/Users/U7/Documents/RAD Studio/Projects/Agora/JvMemoryDataset.pas	�� �� 22 15:00:12 2009
@@ -1,4 +1,4 @@
-{-----------------------------------------------------------------------------
+{-----------------------------------------------------------------------------
 The contents of this file are subject to the Mozilla Public License
 Version 1.1 (the "License"); you may not use this file except in compliance
 with the License. You may obtain a copy of the License at
@@ -1133,10 +1133,8 @@
   begin
     CheckBrowseMode;
     if Filtered <> Value then
-    begin
       inherited SetFiltered(Value);
-      First;
-    end;
+    First;
   end
   else
     inherited SetFiltered(Value);
JvMemoryDataset.diff (779 bytes)

2009-07-22 14:08

 

JvDBUtils.diff (2,410 bytes)
--- D:/jvcl/run/JvDBUtils.pas	�� �� 22 14:29:31 2009
+++ C:/Users/U7/Documents/RAD Studio/Projects/Agora/JvDBUtils.pas	�� �� 22 15:04:10 2009
@@ -1,4 +1,4 @@
-{-----------------------------------------------------------------------------
+{-----------------------------------------------------------------------------
 The contents of this file are subject to the Mozilla Public License
 Version 1.1 (the "License"); you may not use this file except in compliance
 with the License. You may obtain a copy of the License at
@@ -483,7 +483,7 @@
   var
     S: string;
   begin
-    if Field.DataType = ftString then
+    if Field.DataType in [ftString{$IFDEF COMPILER11_UP}, ftWideString{$ENDIF}] then
     begin
       if Value = Null then
         Result := Field.IsNull
@@ -598,7 +598,7 @@
   Field := DataSet.FindField(FieldName);
   if Field = nil then
     Exit;
-  if Field.DataType = ftString then
+  if Field.DataType in [ftString{$IFDEF COMPILER11_UP}, ftWideString{$ENDIF}] then
   begin
     DataSet.DisableControls;
     BookMk := DataSet.GetBookmark;
@@ -856,7 +856,7 @@
   FieldValue := '';
   DateValue := NullDate;
   Exact := Exact or not (FieldType in
-    [ftString, ftDate, ftTime, ftDateTime]);
+    [ftString, {$IFDEF COMPILER11_UP}ftWideString,{$ENDIF} ftDate, ftTime, ftDateTime]);
   if FieldType in [ftDate, ftTime, ftDateTime] then
   begin
     DateValue := StrToDateDef(Value, NullDate);
@@ -870,7 +870,7 @@
     if not (Exact or EmptyValue) then
       FieldValue := ReplaceStr(ReplaceStr(StrMaskSQL(FieldValue),
         '*', '%'), '?', '_');
-    if FieldType = ftString then
+    if FieldType in [ftString{$IFDEF COMPILER11_UP}, ftWideString{$ENDIF}] then
       FieldValue := '''' + FieldValue + '''';
   end;
   LogicOperator := Operator;
@@ -880,7 +880,7 @@
       LogicOperator := '='
     else
     begin
-      if FieldType = ftString then
+      if FieldType in [ftString{$IFDEF COMPILER11_UP}, ftWideString{$ENDIF}] then
         LogicOperator := 'LIKE'
       else
         LogicOperator := '>=';
@@ -905,7 +905,7 @@
   S, Esc: string;
 begin
   Esc := '';
-  if not Exact and (FieldType = ftString) then
+  if not Exact and (FieldType in [ftString{$IFDEF COMPILER11_UP}, ftWideString{$ENDIF}]) then
   begin
     S := ReplaceStr(ReplaceStr(ReplaceStr(Value, '/', '//'),
       '_', '/_'), '%', '/%');
JvDBUtils.diff (2,410 bytes)

ZENsan

2009-07-22 14:09

reporter   ~0015874

I uploaded patch diff files for latest revision 12405

2009-07-22 14:13

 

JvDBUtils - last.diff (2,410 bytes)
--- D:/jvcl/run/JvDBUtils.pas	�� �� 22 14:29:31 2009
+++ C:/Users/U7/Documents/RAD Studio/Projects/Agora/JvDBUtils.pas	�� �� 22 15:09:12 2009
@@ -1,4 +1,4 @@
-{-----------------------------------------------------------------------------
+{-----------------------------------------------------------------------------
 The contents of this file are subject to the Mozilla Public License
 Version 1.1 (the "License"); you may not use this file except in compliance
 with the License. You may obtain a copy of the License at
@@ -483,7 +483,7 @@
   var
     S: string;
   begin
-    if Field.DataType = ftString then
+    if Field.DataType in [ftString{$IFDEF COMPILER12_UP}, ftWideString{$ENDIF}] then
     begin
       if Value = Null then
         Result := Field.IsNull
@@ -598,7 +598,7 @@
   Field := DataSet.FindField(FieldName);
   if Field = nil then
     Exit;
-  if Field.DataType = ftString then
+  if Field.DataType in [ftString{$IFDEF COMPILER12_UP}, ftWideString{$ENDIF}] then
   begin
     DataSet.DisableControls;
     BookMk := DataSet.GetBookmark;
@@ -856,7 +856,7 @@
   FieldValue := '';
   DateValue := NullDate;
   Exact := Exact or not (FieldType in
-    [ftString, ftDate, ftTime, ftDateTime]);
+    [ftString, {$IFDEF COMPILER12_UP}ftWideString,{$ENDIF} ftDate, ftTime, ftDateTime]);
   if FieldType in [ftDate, ftTime, ftDateTime] then
   begin
     DateValue := StrToDateDef(Value, NullDate);
@@ -870,7 +870,7 @@
     if not (Exact or EmptyValue) then
       FieldValue := ReplaceStr(ReplaceStr(StrMaskSQL(FieldValue),
         '*', '%'), '?', '_');
-    if FieldType = ftString then
+    if FieldType in [ftString{$IFDEF COMPILER12_UP}, ftWideString{$ENDIF}] then
       FieldValue := '''' + FieldValue + '''';
   end;
   LogicOperator := Operator;
@@ -880,7 +880,7 @@
       LogicOperator := '='
     else
     begin
-      if FieldType = ftString then
+      if FieldType in [ftString{$IFDEF COMPILER12_UP}, ftWideString{$ENDIF}] then
         LogicOperator := 'LIKE'
       else
         LogicOperator := '>=';
@@ -905,7 +905,7 @@
   S, Esc: string;
 begin
   Esc := '';
-  if not Exact and (FieldType = ftString) then
+  if not Exact and (FieldType in [ftString{$IFDEF COMPILER12_UP}, ftWideString{$ENDIF}]) then
   begin
     S := ReplaceStr(ReplaceStr(ReplaceStr(Value, '/', '//'),
       '_', '/_'), '%', '/%');
JvDBUtils - last.diff (2,410 bytes)

ZENsan

2009-07-22 14:14

reporter   ~0015875

Please do not apply JvDBUtils.diff, but apply JvDBUtils-last.diff.

I mixed up COMPILER12_UP with COMPILER12_UP, COMPILER12_UP is the right

ZENsan

2009-07-22 14:28

reporter   ~0015877

...
I mixed up COMPILER11_UP with COMPILER12_UP, COMPILER12_UP is the right
...
:)

ZENsan

2009-07-30 08:20

reporter   ~0015895

Diff files still will work with latest revision from SVN...

ZENsan

2009-08-03 08:24

reporter   ~0015897

Can someone check this patch?

JvMemoryDataset.diff
JvDBUtils - last.diff

obones

2009-08-04 09:35

administrator   ~0015900

JvMemoryDataset is in.
But JvDBUtils got me thinking: ftWideString is not a new value in D2009, it existed long before. So why limit it to D2009+ ?

ZENsan

2009-08-04 15:01

reporter   ~0015914

Because only in Delphi 2009 working with ftWideString is acceptable. because functions uses method AsString, and this method in Delphi prior to Delphi 2009 for field ftWideString will return ??? marks for unicode symbols.

I think it is not so good...
Maybe I am wrong.

ZENsan

2009-08-04 15:06

reporter   ~0015916

And there is too much work for updating all the functions from string parameter...

I think it is the correct way to change this.

ZENsan

2009-08-13 13:22

reporter   ~0015990

So?

obones

2009-08-13 14:21

administrator   ~0015992

This is now in SVN

Issue History

Date Modified Username Field Change
2009-06-16 14:49 ZENsan New Issue
2009-06-16 14:49 ZENsan Note Added: 0015687
2009-06-16 15:13 ZENsan Note Added: 0015688
2009-06-16 15:38 ZENsan Note Added: 0015689
2009-06-16 19:16 AHUser Note Added: 0015691
2009-06-16 19:16 AHUser Status new => feedback
2009-06-16 19:57 ZENsan Note Added: 0015693
2009-06-16 20:11 AHUser Note Added: 0015694
2009-06-17 08:04 ZENsan Note Added: 0015698
2009-07-07 12:35 ZENsan Note Added: 0015772
2009-07-07 12:36 ZENsan Note Added: 0015773
2009-07-09 13:41 obones Note Added: 0015803
2009-07-17 17:02 ZENsan Note Added: 0015861
2009-07-17 17:02 ZENsan Note Added: 0015862
2009-07-21 11:15 obones Note Added: 0015868
2009-07-22 14:06 ZENsan File Added: JvMemoryDataset.diff
2009-07-22 14:08 ZENsan File Added: JvDBUtils.diff
2009-07-22 14:09 ZENsan Note Added: 0015874
2009-07-22 14:13 ZENsan File Added: JvDBUtils - last.diff
2009-07-22 14:14 ZENsan Note Added: 0015875
2009-07-22 14:28 ZENsan Note Added: 0015877
2009-07-30 08:20 ZENsan Note Added: 0015895
2009-08-03 08:24 ZENsan Note Added: 0015897
2009-08-04 09:35 obones Note Added: 0015900
2009-08-04 15:01 ZENsan Note Added: 0015914
2009-08-04 15:06 ZENsan Note Added: 0015916
2009-08-13 13:22 ZENsan Note Added: 0015990
2009-08-13 14:21 obones Note Added: 0015992
2009-08-13 14:21 obones Status feedback => resolved
2009-08-13 14:21 obones Fixed in Version => Daily / SVN
2009-08-13 14:21 obones Resolution open => fixed
2009-08-13 14:21 obones Assigned To => obones