Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Eigene Komponente mit TField-Properties (https://www.delphipraxis.net/30642-eigene-komponente-mit-tfield-properties.html)

Stevie 27. Sep 2004 15:20


Eigene Komponente mit TField-Properties
 
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.

Stevie 27. Sep 2004 16:13

Re: Eigene Komponente mit TField-Properties
 
Und wieder ein Problem, dass selber gelöst wurde... :zwinker:
Delphi-Quellcode:
RegisterPropertyEditor(TypeInfo(string), TSecurity, 'UserNameField', TDataFieldProperty);
TDataFieldProperty liefert die Feldnamen über die DataSource des Objektes (die Property muss auch DataSource heißen) zurück. Warum klappt die Sache aber mit dem Property DataField?? Weil für jedes TComponent-Objekt dieser PropertyEditor schon registriert ist.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:51 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz