Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:58:57+00:00 2026-06-18T00:58:57+00:00

If we look into the online help of XE2 or XE3 for TObjectList methods

  • 0

If we look into the online help of XE2 or XE3 for TObjectList methods
, we see that the binarysearch function is accessible for the TObjectList. But if we try into XE3 it doesn’t even compile.

For the example, the sort function is available also, but this one compile.

Any idea is welcome.

Sample code :

unit FM_Main;

  interface

  uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Contnrs, Vcl.CheckLst, System.Generics.Collections;

  type
     TTPRODData = class
     private
        FData1 : String;
        FData2 : String;

        FCount : Integer;
     public
        constructor Create; overload;
        destructor Destroy; override;
     end;

     TTPRODDataList = class(TObjectList)

        function GetItem(Index: Integer): TTPRODData;
        procedure SetItem(Index: Integer; const Value: TTPRODData);
     public
        constructor Create; overload;
        destructor  Destroy; override;

        property Items[Index: Integer]: TTPRODData read GetItem write SetItem; default;
        procedure SortOnProductCode;

     end;

    TForm1 = class(TForm)
      Button1: TButton;
      procedure Button1Click(Sender: TObject);
    private
      { Private declarations }
    public
      { Public declarations }
    end;

  var
    Form1: TForm1;

  implementation

  {$R *.dfm}

  //
  // Sort function.
  //
  function CompareProductCode(Item1, Item2: Pointer): Integer;
  begin
     Result := CompareStr(TTPRODData(Item1).FData1, TTPRODData(Item2).FData1);
  end;

  //
  //
  //

  procedure TForm1.Button1Click(Sender: TObject);
  var
     aProdList : TTPRODDataList;
     aDummy : TTPRODData;
     aNdx : Integer;

  begin
     aProdList := TTPRODDataList.Create;

     // This call works.
     aProdList.Sort(CompareProductCode);

     // This call doesn't even compile !
     aProdList.BinarySearch(aDummy, aNdx);
  end;

  { TTPRODData }

  constructor TTPRODData.Create;
  begin
     inherited Create;

     FData1 := '';
     FData2 := '';
     FCount := 0;
  end;

  destructor TTPRODData.Destroy;
  begin
    inherited;
  end;

  { TTPRODDataList }

  constructor TTPRODDataList.Create;
  begin
     inherited Create;
  end;

  destructor TTPRODDataList.Destroy;
  begin
     Clear;

     inherited;
  end;

  function TTPRODDataList.GetItem(Index: Integer): TTPRODData;
  begin
     result := TTPRODData(inherited GetItem(index));
  end;

  procedure TTPRODDataList.SetItem(Index: Integer; const Value: TTPRODData);
  begin
     inherited setItem(index, value);
  end;

  procedure TTPRODDataList.SortOnProductCode;
  begin
     Sort(CompareProductCode);
  end;

  end.

As suggested by David Heffernan, here follow the code for the comparer for the sort function.

For those who are interested, here follow the code for the comparer method:

TTProdComparer = class(TComparer<TTPRODData>)
public
   function Compare(const Item1, Item2: TTPRODData): Integer; override;
end;

And the code :
{ TTProdComparer }
function TTProdComparer.Compare(const Item1, Item2: TTPRODData): Integer;
begin
   Result := CompareStr(Item1.FData1 , Item2.FData1 );
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:58:58+00:00Added an answer on June 18, 2026 at 12:58 am

    The documentation that you have linked to is for the generic container TObjectList<T> from the Generics.Collections unit.

    But the class that you have used in your code is the legacy non-generic container TObjectList from the Contnrs unit.

    The BinarySearch method that you are trying to use only exists on the generic class.

    If you switch to the generic container then you’ll find that you can remove most of the boiler-plate code from your class. It becomes:

    TTPRODDataList = class(TObjectList<TTPRODData>)
    public
      procedure SortOnProductCode;
    end;
    

    You don’t need GetItem, SetItem and Items because the type-safe generic class already has that functionality sorted.

    The only work you have to do is to adapt your sorting code to fit with the somewhat different interface used by the Delphi generic containers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me look into my simple test case: import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import
I have to look into solutions for providing a MySQL database that can handle
So far I know that FileSystemWatcher can look into a folder and if any
I'm slowly dying inside with this request but I've been asked to look into
I have been looking around online to try to find a complete solution but
I have started to look into python and am trying to grasp new things
I want to look into developing mobile applications using HTML5. I'm very new to
I've yet to look into storing files such as Word, Excel, etc. into MongoDB
As I look into documentation of GKScore and GKLeaderboard, there is no way to
Im trying to look into using the WPF WriteableBitmap class to allow my application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.