View Issue Details

IDProjectCategoryView StatusLast Update
0006192JEDI VCL00 JVCL Componentspublic2015-09-14 13:20
ReportermrAssigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.48 
Summary0006192: JvInterpreterAdapter - wrong sorting in SortMethodIdentifier
DescriptionIn TJvInterpreterAdapter.GetValue.GetMethod sorting by inheritance of class is needed to correct call last (by inheritance) defined get method(FGetList) - i observed error there.
I can experimentaly reproduce problem on small set - please add via TJvInterpreterAdapter.SharedAdapter.AddGet method called "Method" in order :
TMyForm
TForm
TChart
TMyGrid
TScrollingWinControl
TWinControl
TControl
TComponent

and after first call TJvInterpreterAdapter.Sort we get wrong order :
TMyGrid
TScrollingWinControl
TChart
TMyForm
TForm
TWinControl
TControl
TComponent

wrong because TMyForm and TForm inherits from TScrollingWinControl, and should be above it to correct call TMyForm.Method instead of TScrollingWinControl.Method.

solution is small change in procedure JvInterpreter.SortMethodIdentifier - from:

function SortMethodIdentifier(Item1, Item2: Pointer): Integer;
begin
  Result := AnsiStrIComp(PChar(TJvInterpreterIdentifier(Item1).Identifier),
    PChar(TJvInterpreterIdentifier(Item2).Identifier));

  if (Result = 0) and (Item1 <> Item2) then
  begin
    if TJvInterpreterMethod(Item1).FClassType.InheritsFrom(TJvInterpreterMethod(Item2).FClassType) then
      Result := -1
    else
    if TJvInterpreterMethod(Item2).FClassType.InheritsFrom(TJvInterpreterMethod(Item1).FClassType) then
      Result := 1;
  end;
end;

to :

function SortMethodIdentifier(Item1, Item2: Pointer): Integer;
begin
  Result := AnsiStrIComp(PChar(TJvInterpreterIdentifier(Item1).Identifier),
    PChar(TJvInterpreterIdentifier(Item2).Identifier));

  if (Result = 0) and (Item1 <> Item2) then
  begin
    if TJvInterpreterMethod(Item1).FClassType.InheritsFrom(TJvInterpreterMethod(Item2).FClassType) then
      Result := -1
    else
      Result := 1;
  end;
end;

i can't clearly explain why it's happend (original code looks good at first glance), but itsems to me that quicksort is not good choice for sorting here. this change, helps in my cases so far.

i use delphi xe2, all tests were done on "Debug Configuration"
Additional Informationbellow is my test case method from dunit:

type
  TMyForm = class(TForm);
  TMyGrid = class(TWinControl);
  TJvAA = class(TJvInterpreterAdapter);
  TJvMA = class(TJvInterpreterMethod);

procedure TTestItpt_Basics.Test_MethodOrderEx4;
var
  itpt: TJvInterpreterProgram;

  procedure DumpGL(fn: string);
  var
    i: Integer;
    sl: TStringList;
  begin
    sl := TStringList.Create;
    for i := 0 to itpt.SharedAdapter.GetList.Count - 1 do
      sl.Add(TjvMA(itpt.SharedAdapter.GetList.Items[i]).FClassType.ClassName);
    sl.SaveToFile(fn);
    sl.Free;
  end;

begin
  itpt := TJvInterpreterProgram.Create(nil);
  try
    TJvAA(itpt.SharedAdapter).Clear;
    itpt.SharedAdapter.AddGet(TMyForm, 'Method', nil, 0, [], varEmpty);
    itpt.SharedAdapter.AddGet(TForm, 'Method', nil, 0, [], varEmpty);
    itpt.SharedAdapter.AddGet(TChart, 'Method', nil, 0, [], varEmpty);
    itpt.SharedAdapter.AddGet(TMyGrid, 'Method', nil, 0, [], varEmpty);
    itpt.SharedAdapter.AddGet(TScrollingWinControl, 'Method', nil, 0, [], varEmpty);
    itpt.SharedAdapter.AddGet(TWinControl, 'Method', nil, 0, [], varEmpty);
    itpt.SharedAdapter.AddGet(TControl, 'Method', nil, 0, [], varEmpty);
    itpt.SharedAdapter.AddGet(TComponent, 'Method', nil, 0, [], varEmpty);

    DumpGL('cre0.txt');
    TJvAA(itpt.SharedAdapter).Sort;
    DumpGL('cre1.txt');
  finally
    itpt.Free;
  end;
end;
TagsNo tags attached.

Activities

obones

2013-12-13 11:02

administrator   ~0020740

Please try with the latest JVCL version in GIT (or daily zip) and then send us a zipped file containing the sources of an application showing the issue.

2013-12-13 21:27

 

jviTest.zip (9,396 bytes)

mr

2013-12-13 21:48

reporter   ~0020844

i checked git version also.
i uploaded zip with dunit project - in "TTest1" "Test_MethodOrder" demonstrated result after wrong sort, "Test_MethodOrderOk" is modified test with proposed "SortMethodIdentifier". Of course it's abstract and simplified example - and without real script demonstrating problem, but i think it's not necessary.

obones

2013-12-18 15:24

administrator   ~0020878

This is now fixed in GIT

Issue History

Date Modified Username Field Change
2013-08-27 00:33 mr New Issue
2013-12-13 11:02 obones Note Added: 0020740
2013-12-13 11:02 obones Status new => feedback
2013-12-13 21:27 mr File Added: jviTest.zip
2013-12-13 21:48 mr Note Added: 0020844
2013-12-16 17:04 obones Status feedback => acknowledged
2013-12-18 15:24 obones Note Added: 0020878
2013-12-18 15:24 obones Status acknowledged => resolved
2013-12-18 15:24 obones Fixed in Version => Daily / GIT
2013-12-18 15:24 obones Resolution open => fixed
2013-12-18 15:24 obones Assigned To => obones
2015-09-14 13:20 obones Fixed in Version Daily / GIT => 3.48