将包分成2个,一个是运行包,一个是设计包。所有的 REG 代码放在设计包。设计包的代码比如像下面这样。
unit ZHANGREG;
interface
uses
{$IFDEF VER130}DsgnIntf, {$ELSE}DesignIntf, DesignEditors,{$ENDIF}Classes,Typinfo,DB;
TYPE
TDBStringProperty = class(TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure GetValueList(List: TStrings); virtual;
procedure GetValues(Proc: TGetStrProc); override;
end;
TDataFieldProperty = class(TDBStringProperty)
public
function GetDataSourcePropName: string; virtual;
procedure GetValueList(List: TStrings); override;
end;
procedure Register;
implementation
USES Outlook,wiaTile,Gradpan,gwrlr,backup,
ColorBtns,Comm32,BestWiatile ,CrossDataSet,
Encryp,DsPanel,Trayicon,SPComm,ping,DBStatusBar,
OLItemsProp,DBEditMS,ObjectDataset;
{ TDBStringProperty }
function TDBStringProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paSortList, paMultiSelect];
end;
procedure TDBStringProperty.GetValueList(List: TStrings);
begin
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);
finally
Values.Free;
end;
end;
{ TDataFieldProperty }
function TDataFieldProperty.GetDataSourcePropName: string;
begin
Result := 'OriginalDataSource';
end;
procedure TDataFieldProperty.GetValueList(List: TStrings);
var
DataSource: TDataSource ;
begin
DataSource := GetObjectProp(GetComponent(0), GetDataSourcePropName) as TDataSource;
if (DataSource <> nil) and (DataSource.DataSet <> nil) then
DataSource.DataSet.GetFieldNames(List);
end;
procedure Register;
begin
RegisterComponents('MSTAR', [TOutlook]);
RegisterPropertyEditor (TypeInfo(TOutlookItems),
TOutlook, 'Items', TOLITemsProperty);
RegisterPropertyEditor(TypeInfo(string), TCrossDataSet, 'ColField', TDataFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TCrossDataSet, 'RowField', TDataFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TCrossDataSet, 'DataField', TDataFieldProperty);
RegisterPropertyEditor(TypeInfo(string), TDBStatusPanel, 'DataField', TDataFieldProperty);
RegisterComponents('MSTAR', [TbestwiaTile]);
RegisterComponents('MSTAR', [TwiaTile]);
RegisterComponents('MSTAR', [TGradPan]);
RegisterComponents('MSTAR', [TGridWithRuler]);
RegisterComponents('MSTAR', [TDBGridWithRuler]);
RegisterComponents('MSTAR', [TBackupFile]);
RegisterComponents('MSTAR', [TColor95Button]);
RegisterComponents('MSTAR', [TComm32]);
RegisterComponents('MSTAR', [TTomEncryption]);
RegisterComponents('MSTAR', [TDsPanel]);
RegisterComponents('MSTAR', [TTrayIcon]);
RegisterComponents('MSTAR', [TComm]);
RegisterComponents('MSTAR', [TPing]);
RegisterComponents('Data Controls', [TDBEditMS]);
RegisterComponents('MSTAR', [TCrossDataSet]);
RegisterComponents('MSTAR', [TObjectDataSet]);
RegisterComponents('Data Controls', [TDBStatusBar]);
end;
end.