unit CompositionDialogProperty;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, DB, PropEdits, DBPropEdits, TypInfo, Controls;
type
{ TDataSourceProperty }
TDataSourceProperty = class(TPersistent)
private
FDataField: string;
FDataSource: TDataSource;
procedure SetDataField(AValue: string);
procedure SetDataSource(AValue: TDataSource);
published
property DataSource: TDataSource read FDataSource write SetDataSource;
property DataField: string read FDataField write SetDataField;
end;
type
{ TStatusCompositionFilter }
TStatusCompositionFilter = class(TPersistent)
private
FKeyField: string;
FListField: string;
FListFieldIndex: integer;
FListSource: TDataSource;
procedure SetKeyField(AValue: string);
procedure SetListField(AValue: string);
procedure SetListFieldIndex(AValue: integer);
procedure SetListSource(AValue: TDataSource);
published
property ListFieldIndex: integer read FListFieldIndex write SetListFieldIndex;
property ListSource: TDataSource read FListSource write SetListSource;
property KeyField: string read FKeyField write SetKeyField;
property ListField: string read FListField write SetListField;
end;
type
{ TStatusComposition }
TStatusComposition = class(TDataSourceProperty)
private
FKeyField: string;
FListField: string;
FListFieldIndex: integer;
FListSource: TDataSource;
procedure SetKeyField(AValue: string);
procedure SetListField(AValue: string);
procedure SetListFieldIndex(AValue: integer);
procedure SetListSource(AValue: TDataSource);
published
property ListFieldIndex: integer read FListFieldIndex write SetListFieldIndex;
property ListSource: TDataSource read FListSource write SetListSource;
property KeyField: string read FKeyField write SetKeyField;
property ListField: string read FListField write SetListField;
end;
type
TDirectoryComposition = class;
type
{ TDescription }
TDescription = class(TPersistent)
private
FDescriptionField: string;
FXML: boolean;
FParent: TDirectoryComposition;
procedure SetDescriptionField(AValue: string);
procedure SetXML(AValue: boolean);
protected
property Parent: TDirectoryComposition read FParent;
published
property DescriptionField: string read FDescriptionField write SetDescriptionField;
property XML: boolean read FXML write SetXML;
public
constructor Create(AParent: TDirectoryComposition);
end;
type
{ TDirectoryComposition }
TDirectoryComposition = class(TDataSourceProperty)
private
FDescription: TDescription;
FImageIndex: integer;
FImageList: TimageList;
FKeyField: string;
FOnDirectoryCompositionError: TNotifyEvent;
FParentField: string;
procedure SetImageIndex(AValue: integer);
procedure SetImageList(AValue: TimageList);
procedure SetKeyField(AValue: string);
procedure SetOnDirectoryCompositionError(AValue: TNotifyEvent);
procedure SetParentField(AValue: string);
public
constructor Create;
destructor Destroy; override;
published
property KeyField: string read FKeyField write SetKeyField;
property ParentField: string read FParentField write SetParentField;
property Description: TDescription read FDescription;
property ImageList: TimageList read FImageList write SetImageList;
property ImageIndex: integer read FImageIndex write SetImageIndex;
property OnDirectoryCompositionError: TNotifyEvent
read FOnDirectoryCompositionError write SetOnDirectoryCompositionError;
end;
type
{ TListComposition }
TListComposition = class(TDataSourceProperty)
private
FKeyField: string;
FListField: string;
FListFieldIndex: integer;
FListSource: TDataSource;
FOnListCompositionError: TNotifyEvent;
FStatusComposition: TStatusComposition;
procedure SetKeyField(AValue: string);
procedure SetListField(AValue: string);
procedure SetListFieldIndex(AValue: integer);
procedure SetListSource(AValue: TDataSource);
procedure SetOnListCompositionError(AValue: TNotifyEvent);
procedure SetStatusComposition(AValue: TStatusComposition);
public
constructor Create;
destructor Destroy; override;
published
property ListFieldIndex: integer read FListFieldIndex write SetListFieldIndex;
property ListSource: TDataSource read FListSource write SetListSource;
property KeyField: string read FKeyField write SetKeyField;
property ListField: string read FListField write SetListField;
property StatusComposition: TStatusComposition
read FStatusComposition write SetStatusComposition;
property OnListCompositionError: TNotifyEvent
read FOnListCompositionError write SetOnListCompositionError;
end;
type
{ TSubFieldProperty }
TSubFieldProperty = class(TFieldProperty)
public
procedure FillValues(const Values: TStringList); override;
end;
implementation
{ TStatusCompositionFilter }
procedure TStatusCompositionFilter.SetKeyField(AValue: string);
begin
if FKeyField = AValue then
Exit;
FKeyField := AValue;
end;
procedure TStatusCompositionFilter.SetListField(AValue: string);
begin
if FListField = AValue then
Exit;
FListField := AValue;
end;
procedure TStatusCompositionFilter.SetListFieldIndex(AValue: integer);
begin
if FListFieldIndex = AValue then
Exit;
FListFieldIndex := AValue;
end;
procedure TStatusCompositionFilter.SetListSource(AValue: TDataSource);
begin
if FListSource = AValue then
Exit;
FListSource := AValue;
end;
{ TSubFieldProperty }
procedure TSubFieldProperty.FillValues(const Values: TStringList);
var
DataSource: TDataSource;
begin
DataSource := GetObjectProp((GetComponent(0) as TDescription).Parent, 'DataSource') as
TDataSource;
ListDataSourceFields(DataSource, Values);
end;
{ TDescription }
procedure TDescription.SetDescriptionField(AValue: string);
begin
if FDescriptionField = AValue then
Exit;
FDescriptionField := AValue;
end;
procedure TDescription.SetXML(AValue: boolean);
begin
if FXML = AValue then
Exit;
FXML := AValue;
end;
constructor TDescription.Create(AParent: TDirectoryComposition);
begin
FParent := AParent;
end;
{ TListComposition }
procedure TListComposition.SetKeyField(AValue: string);
begin
if FKeyField = AValue then
Exit;
FKeyField := AValue;
end;
procedure TListComposition.SetListField(AValue: string);
begin
if FListField = AValue then
Exit;
FListField := AValue;
end;
procedure TListComposition.SetListFieldIndex(AValue: integer);
begin
if FListFieldIndex = AValue then
Exit;
FListFieldIndex := AValue;
end;
procedure TListComposition.SetListSource(AValue: TDataSource);
begin
if FListSource = AValue then
Exit;
FListSource := AValue;
end;
procedure TListComposition.SetOnListCompositionError(AValue: TNotifyEvent);
begin
if FOnListCompositionError = AValue then
Exit;
FOnListCompositionError := AValue;
end;
procedure TListComposition.SetStatusComposition(AValue: TStatusComposition);
begin
if FStatusComposition = AValue then
Exit;
FStatusComposition := AValue;
end;
constructor TListComposition.Create;
begin
FStatusComposition := TStatusComposition.Create;
end;
destructor TListComposition.Destroy;
begin
FStatusComposition.Free;
inherited Destroy;
end;
{ TDirectoryComposition }
procedure TDirectoryComposition.SetKeyField(AValue: string);
begin
if FKeyField = AValue then
Exit;
FKeyField := AValue;
end;
procedure TDirectoryComposition.SetImageList(AValue: TimageList);
begin
if FImageList = AValue then
Exit;
FImageList := AValue;
end;
procedure TDirectoryComposition.SetImageIndex(AValue: integer);
begin
if FImageIndex = AValue then
Exit;
FImageIndex := AValue;
end;
procedure TDirectoryComposition.SetOnDirectoryCompositionError(AValue: TNotifyEvent);
begin
if FOnDirectoryCompositionError = AValue then
Exit;
FOnDirectoryCompositionError := AValue;
end;
procedure TDirectoryComposition.SetParentField(AValue: string);
begin
if FParentField = AValue then
Exit;
FParentField := AValue;
end;
constructor TDirectoryComposition.Create;
begin
FDescription := TDescription.Create(Self);
end;
destructor TDirectoryComposition.Destroy;
begin
FDescription.Free;
inherited Destroy;
end;
{ TStatusComposition }
procedure TStatusComposition.SetListFieldIndex(AValue: integer);
begin
if FListFieldIndex = AValue then
Exit;
FListFieldIndex := AValue;
end;
procedure TStatusComposition.SetKeyField(AValue: string);
begin
if FKeyField = AValue then
Exit;
FKeyField := AValue;
end;
procedure TStatusComposition.SetListField(AValue: string);
begin
if FListField = AValue then
Exit;
FListField := AValue;
end;
procedure TStatusComposition.SetListSource(AValue: TDataSource);
begin
if FListSource = AValue then
Exit;
FListSource := AValue;
end;
{ TDataSourceProperty }
procedure TDataSourceProperty.SetDataSource(AValue: TDataSource);
begin
if FDataSource = AValue then
Exit;
FDataSource := AValue;
end;
procedure TDataSourceProperty.SetDataField(AValue: string);
begin
if FDataField = AValue then
Exit;
FDataField := AValue;
end;
initialization
RegisterPropertyEditor(TypeInfo(string), TDataSourceProperty,
'DataField', TFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TDirectoryComposition,
'KeyField', TFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TDirectoryComposition,
'ParentField', TFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TDescription,
'DescriptionField', TSubFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TStatusComposition,
'KeyField', TLookupFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TStatusComposition, 'ListField',
TLookupFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TListComposition,
'KeyField', TLookupFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TListComposition, 'ListField',
TLookupFieldProperty);
end.