How to use TcxCustomDataSource in TcxExtLookupComboBox?

I am using TcxExtLookupComboBox from Devexpress and am trying to implement my own data source. I installed customdatasource as follows:

procedure TMainForm.FormCreate(Sender: TObject);
begin
  fDataSource := TMyDataSource.Create;
  cbotestSearch.Properties.View.DataController.CustomDataSource := fDataSource;
end;

Here is the TMyDataSource:

unit Datasource;

interface

uses
  Classes,
  IBQuery,
  SysUtils,
  cxCustomData;

type
  TSearchItem = class
    private
      BoldID: String;
      Display: String
  end;

  TMyDataSource = class(TcxCustomDataSource)
  private
    fSearchList: TList;
  protected
    function GetRecordCount: Integer; override;
    function GetValue(ARecordHandle: TcxDataRecordHandle; AItemHandle: TcxDataItemHandle): Variant; override;
  public
    constructor Create;
    destructor Destroy; override;
    procedure GetData;
  end;

implementation

constructor TMyDataSource.Create;
begin
  inherited Create;
  fSearchList := TList.Create;
end;

destructor TMyDataSource.Destroy;
begin
  FreeAndNil(fSearchList);
  inherited;
end;

procedure TMyDataSource.GetData;
var
  vItem: TSearchItem;
begin
  fSearchList.Clear;

  vItem := TSearchItem.Create;
  vItem.BoldID  := '1000';
  vItem.Display := 'test';
  fSearchList.Add(vItem);

  vItem := TSearchItem.Create;
  vItem.BoldID  := '1100';
  vItem.Display := 'test2';
  fSearchList.Add(vItem);

  DataChanged;    // Don't do anything as provider is nil
end;

function TMyDataSource.GetRecordCount: Integer;
begin
  // Is never entered
  Result := fSearchList.Count;
end;

function TMyDataSource.GetValue(ARecordHandle: TcxDataRecordHandle;
  AItemHandle: TcxDataItemHandle): Variant;
begin
  // Is never entered
  Result := 'Test';
end;

end.

The problem is that TMyDataSource.GetValue is never called. Any hint how to fix?

Update 1: I have one more hint. If I have one step in the DataChanged method that should call GetValue, it looks like this:

procedure TcxCustomDataSource.DataChanged;
begin
  if Provider = nil then Exit;

  // Code using Provider
end;

and the provider in this case is zero. But I assigned a Datasource to Forms oncreate, as you can see.

+3
source share
1 answer

cxExtLookupComboBox DB ~. TcxCustomDataSource . , :-( , :

http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=AS10025

+1

Source: https://habr.com/ru/post/1757805/


All Articles