rickard67 / Emmet-Pascal

Emmet components for use in Delphi or Lazarus
Other
10 stars 11 forks source link

StringList.Sorted is reset and then we have exception #9

Closed Alexey-T closed 2 years ago

Alexey-T commented 2 years ago

I pass Sorted stringlist. then you do:

procedure TEmmet.AddHTMLTagListForValidation(const AList: TStringList);
begin
  if not Assigned(AList) or (AList.Count = 0) then Exit;

  // Ignore and exit if list is already populated
  if Assigned(FHTMLTagList) then Exit;

  // Create a sorted list of added tags
  FHTMLTagList := TStringList.Create;
  FHTMLTagList.Assign(AList);
  FHTMLTagList.CaseSensitive := False;
  FHTMLTagList.Sort;

  if not FHTMLTagList.Sorted then //Alex added
    raise exception.create('dd'); //raised!!   
end;

Sorted is reset, then Find method gives the exception. FPC 3.2.3.

Alexey-T commented 2 years ago

How FPC implements Sorted: it calls SortStyle:= sslAuto. then:

procedure TStringList.SetSortStyle(AValue: TStringsSortStyle);
begin
  if FSortStyle=AValue then Exit;
  if (AValue=sslAuto) then
    Sort;
  FSortStyle:=AValue;
end;
Alexey-T commented 2 years ago

Fix is: change FHTMLTagList.Sort; to FHTMLTagList.Sorted := True;