Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Базы данных и репортинг > Проблема при создании свойства DataFied


Автор: FShadow 17.8.2008, 13:00
Вопрос в следующем.
При написании такого кода: property DataField: WideString read GetDataField write SetDataField;
в инспекторе объектов DataField отображается как комбо со списком полей таблицы.

Если просто переименовываю свойство в KeyField не меняя его реализации, то поле KeyField отображается как string поле.

В чем разница и как сделать свое свойство с выпадающим списком полей таблицы?

Вот весь текст компонента:
Код

type
  TfsDBTreeView = class(TTreeView)
  private
    FDataLink: TFieldDataLink;
    function GetKeyField: WideString;
    function GetDataSource: TDataSource;
    procedure SetKeyField(Value: WideString);
    procedure SetDataSource(Value: TDataSource);
  protected
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property KeyField: WideString read GetKeyField write SetKeyField;
    property DataSource: TDataSource read GetDataSource write SetDataSource;
  end;

implementation

{ TfsDBTree }

constructor TfsDBTreeView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FDataLink := TFieldDataLink.Create;
  FDataLink.Control := Self;

end;

destructor TfsDBTreeView.Destroy;
begin
  FDataLink.Free;
  FDataLink := nil;

  inherited Destroy;
end;

procedure TfsDBTreeView.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (FDataLink <> nil) and
    (AComponent = DataSource) then DataSource := nil;
end;

function TfsDBTreeView.GetKeyField: WideString;
begin
  Result := FDataLink.FieldName;
end;

procedure TfsDBTreeView.SetKeyField(Value: WideString);
begin
  FDataLink.FieldName := Value;
end;

function TfsDBTreeView.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;

procedure TfsDBTreeView.SetDataSource(Value: TDataSource);
begin
  if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
    FDataLink.DataSource := Value;
  if Value <> nil then Value.FreeNotification(Self);
end;




Автор: remax 20.8.2008, 03:28
посмотри тему "редактор свойств - создание, использование и т.п."  smile 

Автор: FShadow 20.8.2008, 20:03
Ооо!!! Большой респект за подсказку!!! smile 
Я уж думал никто не сможет подсказать  smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)