home *** CD-ROM | disk | FTP | other *** search
- unit CascCReg;
- { Register Unit for CascCont}
- interface
-
- procedure Register;
-
- implementation
- uses
- Windows,SysUtils, Classes, DB,DsgnIntf, Controls,CascCont,TypInfo
- ;
-
- { TDBStringProperty and partially TCascadeFieldProperty is
- Copyright Borland. I had to copy-paste it, because it's not
- accesible in DBReg. (Please correct me if I got something wrong
- here.
- }
-
- type
- TCascadeFieldProperty = class(TStringProperty)
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure GetValueList(List: TStrings);
- procedure GetValues(Proc: TGetStrProc); override;
- end;
-
- function TCascadeFieldProperty.GetAttributes: TPropertyAttributes;
- begin
- Result := [paValueList, paSortList, paMultiSelect];
- end;
-
- procedure TCascadeFieldProperty.GetValues(Proc: TGetStrProc);
- var
- I: Integer;
- Values: TStringList;
- begin
- Values := TStringList.Create;
- try
- GetValueList(Values);
- for I := 0 to Values.Count - 1 do Proc(Values[I]);
- finally
- Values.Free;
- end;
- end;
-
- procedure TCascadeFieldProperty.GetValueList(List: TStrings);
- var
- Instance: TComponent;
- PropInfo: PPropInfo;
- DataSource: TDataSource;
- begin
- Instance := GetComponent(0);
- PropInfo := TypInfo.GetPropInfo(Instance.ClassInfo, 'CascadeSource');
- if (PropInfo <> nil) and (PropInfo^.PropType^.Kind = tkClass) then
- begin
- DataSource := TObject(GetOrdProp(Instance, PropInfo)) as TDataSource;
- if (DataSource <> nil) and (DataSource.DataSet <> nil) then
- DataSource.DataSet.GetFieldNames(List);
- end;
- end;
-
- {---------------------------- Property editor ---------------------------------}
- { A special case of TDataFieldGroup Property.
- Only shows the first field of the general form XXXX_First, XXXX_Second,
- with same XXXX in a row.
- This is a candidate for a multiple selection key of DBCheckGroup}
-
- type
- TDataFieldGroupProperty = class(TStringProperty)
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure GetValues(Proc: TGetStrProc); override;
- end;
-
-
- { ------------------------------- TDataFieldGroupProperty --------------------}
- function TDataFieldGroupProperty.GetAttributes: TPropertyAttributes;
- begin
- Result:=[paValueList, paSortList,paMultiSelect];
- end;
-
- procedure TDataFieldGroupProperty.GetValues(Proc: TGetStrProc);
- var UPos,I,Len: Integer;
- CTable:TDataSet;
- CDataSource:TDataSource;
- LastGroup,CurGroup: string;
- FD: TFieldDef;
- begin
- CDataSource:=(TDBCascCheckGroup(GetComponent(0))).DataSource;
- if CDataSource = nil then exit;
- CTable:=CDataSource.DataSet;
- if (CTable = nil) or not CTable.Active then exit;
-
- LastGroup:='';
- for i := 0 to CTable.FieldDefs.Count - 1 do
- begin
- FD:= CTable.FieldDefs.Items[i];
- if FD.DataType <> ftBoolean then continue;
- UPos:=Pos('_',FD.Name);
- if Upos <=1 then continue; { Skip if no _ or leading _ }
- CurGroup:=Copy(FD.Name,1,UPos-1);
- if CompareText(CurGroup,LastGroup) = 0 then
- continue; { Skip if same group }
- LastGroup:=CurGroup;
- Proc(CurGroup);
- end;
- end;
-
- { TDBStringProperty }
-
- type
- TDBStringProperty = class(TStringProperty)
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure GetValueList(List: TStrings); virtual; abstract;
- procedure GetValues(Proc: TGetStrProc); override;
- end;
-
- function TDBStringProperty.GetAttributes: TPropertyAttributes;
- begin
- Result := [paValueList, paSortList, paMultiSelect];
- end;
-
- procedure TDBStringProperty.GetValues(Proc: TGetStrProc);
- var
- I: Integer;
- Values: TStringList;
- begin
- Values := TStringList.Create;
- try
- GetValueList(Values);
- for I := 0 to Values.Count - 1 do Proc(Values[I]);
- finally
- Values.Free;
- end;
- end;
-
- { TDataFieldProperty }
- type
- TDataFieldProperty = class(TDBStringProperty)
- public
- function GetDataSourcePropName: string; virtual;
- procedure GetValueList(List: TStrings); override;
- end;
-
- function TDataFieldProperty.GetDataSourcePropName: string;
- begin
- Result := 'DataSource';
- end;
-
- procedure TDataFieldProperty.GetValueList(List: TStrings);
- var
- Instance: TComponent;
- PropInfo: PPropInfo;
- DataSource: TDataSource;
- begin
- Instance := GetComponent(0);
- PropInfo := TypInfo.GetPropInfo(Instance.ClassInfo, GetDataSourcePropName);
- if (PropInfo <> nil) and (PropInfo^.PropType^.Kind = tkClass) then
- begin
- DataSource := TObject(GetOrdProp(Instance, PropInfo)) as TDataSource;
- if (DataSource <> nil) and (DataSource.DataSet <> nil) then
- DataSource.DataSet.GetFieldNames(List);
- end;
- end;
-
- type
- TListFieldProperty = class(TDataFieldProperty)
- public
- function GetDataSourcePropName: string; override;
- end;
-
- function TListFieldProperty.GetDataSourcePropName: string;
- begin
- Result := 'ListSource';
- end;
-
- procedure Register;
- begin
- RegisterComponents('DBCasc',[
- TDBCascCheckBox,
- TDBCascEdit,
- TDBCascMemo,
- TDBCascLookupCombo,
- TDBCascCheckGroup,
- TDBCascDateEdit
- ]);
- RegisterPropertyEditor(TypeInfo(string), TDBCascLookupCombo, 'CascadeField',
- TCascadeFieldProperty);
- RegisterPropertyEditor(TypeInfo(string), TDBCascCheckBox, 'CascadeField',
- TCascadeFieldProperty);
- RegisterPropertyEditor(TypeInfo(string), TDBCascEdit, 'CascadeField',
- TCascadeFieldProperty);
- RegisterPropertyEditor(TypeInfo(string), TDBCascMemo, 'CascadeField',
- TCascadeFieldProperty);
- RegisterPropertyEditor(TypeInfo(string), TDBCascCheckGroup, 'CascadeField',
- TCascadeFieldProperty);
- RegisterPropertyEditor(TypeInfo(string), TDBCascDateEdit, 'CascadeField',
- TCascadeFieldProperty);
- RegisterPropertyEditor(TypeInfo(string), TDBCascCheckGroup, 'ListField',
- TListFieldProperty);
- RegisterPropertyEditor(TypeInfo(string),TDBCascCheckGroup,
- 'DataFieldGroup',TDataFieldGroupProperty);
- end;
-
-
- end.
-
-