gpt4 book ai didi

delphi - 如何在 TcxExtLookupComboBox 中使用 TcxCustomDataSource?

转载 作者:行者123 更新时间:2023-12-03 15:58:47 31 4
gpt4 key购买 nike

我使用 Devexpress 的 TcxExtLookupComboBox 并尝试实现自定义数据源。我已经像这样设置了自定义数据源:

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

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.

问题是 TMyDataSource.GetValue 从未被调用。有任何提示如何修复吗?

更新 1:我在这里还有另一个提示。如果我单步执行 DataChanged 方法,应该会导致调用 GetValue,如下所示:

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

// Code using Provider
end;

在这种情况下,Provider 为零。但我已经在 Forms oncreate 中分配了数据源,如您所见。

最佳答案

cxExtLookupComboBox 只能与 DB~views 一起使用。此类 View 无法接受 TcxCustomDataSource 对象的实例作为数据源。因此,您的代码将无法工作:-(。有建议在将来实现此功能,并注册于:

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

关于delphi - 如何在 TcxExtLookupComboBox 中使用 TcxCustomDataSource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3395739/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com