Вопрос в следующем. При написании такого кода: 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;
|
|