Einzelnen Beitrag anzeigen

Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.009 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#1

Eigene Komponente mit TField-Properties

  Alt 27. Sep 2004, 15:20
Hallo Leute,

ich versuche, eine Komponente zu schreiben, die mehrere Properties vom Typ TField hat. Allerdings scheitere ich daran, sie im OI auch mit der DropDownList zu versehen. Wenn ich ein Feld DataField nenne, dann klappt das, heißt es anders, dann nicht. Muss ich für die Properties irgendeinen PropertyEditor oder so registrieren?? Bitte helft mir! Hier mein SourceCode:
Delphi-Quellcode:
unit Security;

interface

uses
  Windows, Messages, SysUtils, Classes, DBCtrls, DB;

type
  TSecurity = class(TComponent)
  private
    FDataLink: TFieldDataLink;
    FUserNameDataLink: TFieldDataLink;
    FPasswordDataLink: TFieldDataLink;
    function GetDataSource: TDataSource;
    function GetField(const Index: Integer): string;
    procedure SetDataSource(const Value: TDataSource);
    procedure SetField(const Index: Integer; const Value: string);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property UserNameField: string index 2 read GetField write SetField;
    property PasswordField: string index 1 read GetField write SetField;
    property DataField: string index 0 read GetField write SetField;
    property DataSource: TDataSource read GetDataSource write SetDataSource;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Beispiele', [TSecurity]);
end;

{ TSecurity }

constructor TSecurity.Create(AOwner: TComponent);
begin
  inherited;
  FDataLink := TFieldDataLink.Create;
  FUserNameDataLink := TFieldDataLink.Create;
  FPasswordDataLink := TFieldDataLink.Create;
end;

destructor TSecurity.Destroy;
begin
  FreeAndNil(FDataLink);
  FreeAndNil(FUserNameDataLink);
  FreeAndNil(FPasswordDataLink);
  inherited;
end;

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

function TSecurity.GetField(const Index: Integer): string;
begin
  case Index of
    0: Result := FDataLink.FieldName;
    1: Result := FPasswordDataLink.FieldName;
    2: Result := FUserNameDataLink.FieldName;
  end;
end;

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

procedure TSecurity.SetField(const Index: Integer; const Value: string);
begin
  case Index of
    0: FDataLink.FieldName := Value;
    1: FPasswordDataLink.FieldName := Value;
    2: FUserNameDataLink.FieldName := Value;
  end;
end;

end.
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat