Hola a todos,
Os explico muy por encima lo que quiero hacer, tengo un componente, del cual he creado un TCollection para poder especificar ciertos valores de los campos de una tabla, y resulta que cuando creo el componente, quiero que se me inicialice esa colection con los campos que hay en una tabla. Me parece que no me explico, a ver si con un poco de código lo consigo explicar:
Código:
{ TFieldItem }
TFieldItem = class(TCollectionItem)
private
FName: String;
FColTitle: String;
FDefaultSearch: Boolean;
FSize: Integer;
protected
function GetDisplayName: String; Override;
public
procedure Assign(Source: TPersistent);
procedure SetDefaultSearch (Value: Boolean);Virtual;
published
property Name: String read FName write FName;
property ColTitle: String read FColTitle write FColTitle;
property DefaultSearch:Boolean read FDefaultSearch write SetDefaultSearch;
property Size: Integer read FSize write FSize;
end;
{ TFieldList }
TFieldList = class(TCollection)
private
FOwner: TPersistent;
function GetItem(Index: Integer): TFieldItem;
procedure SetItem(Index: Integer; Value: TFieldItem);
protected
public
function GetOwner: TPersistent; Override;
constructor Create(AOwner: TPersistent);
destructor Destroy; override;
procedure Add(AName: String; ADefaultSearch:Boolean; AColTitle: String;
ASize: Integer);
procedure Clear;
property Items[Index: Integer]: TFieldItem read GetItem write SetItem; default;
published
end;
TDBViewer = class(TComponent)
private
FDataSet: TDataSet;
FReturnParams: Integer;
FReturnValues: array of Variant;
FFieldDefs: TFieldList;
FFormTitle : String;
FFormWidth: Integer;
FFormHeight:Integer;
FEditColor: TColor;
FGridColor: TColor;
FDataLink: TFieldDataLink;
function GetDataField: string;
function GetDataSource: TDataSource;
procedure SetDataField(const Value: string);
procedure SetDataSource(Value: TDataSource);
public
procedure SetDataSet(Value: TDataSet); virtual;
procedure SetReturnParams(Value: Integer); virtual;
function GetDataSet: TDataSet; virtual;
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure Execute;
function ReturnParamValues (Param:Integer):Variant;
published
property FieldDefs: TFieldList read FFieldDefs;
property DataSet: TDataSet read GetDataSet write SetDataSet;
property ReturnParams: Integer read FReturnParams Write SetReturnParams default 1;
property FormTitle: String read FFormTitle Write FFormTitle;
property FormHeight: Integer read FFormHeight Write FFormHeight;
property FormWidth: Integer read FFormWidth Write FFormWidth;
property EditColor: TColor read FEditColor Write FEditColor;
property GridColor: TColor read FGridColor write FGridColor;
end;
Pues bien, lo que quiero es que cuando se cree un DBViewer la propiedad FFieldDefs contenga las columnas que hay dentro del DataSet (eso en tiempo de diseño), pero que cuando se ejecute la aplicación, yo pueda acceder a esos items (y a sus valores, tanto si se han cambiando como si no).
Espero haberme explicado, y gracias a todos