TPublishedPropertyManager can now (if desired) handle unknown properties

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2378 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
inoussa
2012-04-03 17:37:52 +00:00
parent 1b9947bf0c
commit 1287ce1650

View File

@@ -29,6 +29,9 @@ Type
TPublishedPropertyManager = class(TInterfacedObject,IPropertyManager) TPublishedPropertyManager = class(TInterfacedObject,IPropertyManager)
Private Private
FParent : TObject; FParent : TObject;
FUnknownProps : IPropertyManager;
FHandleUnknownProps : Boolean;
private
procedure Error(Const AMsg:string);overload;{$IFDEF USE_INLINE}inline;{$ENDIF} procedure Error(Const AMsg:string);overload;{$IFDEF USE_INLINE}inline;{$ENDIF}
procedure Error(Const AMsg:string; Const AArgs : array of const);overload; procedure Error(Const AMsg:string; Const AArgs : array of const);overload;
Protected Protected
@@ -39,7 +42,10 @@ Type
procedure Clear(); procedure Clear();
procedure Copy(ASource:IPropertyManager; Const AClearBefore : Boolean); procedure Copy(ASource:IPropertyManager; Const AClearBefore : Boolean);
Public Public
constructor Create(AParent : TObject); constructor Create(
AParent : TObject;
const AHandleUnknownProps : Boolean = False
);
End; End;
function IsStrEmpty(Const AStr:String):Boolean;{$IFDEF USE_INLINE}inline;{$ENDIF}overload; function IsStrEmpty(Const AStr:String):Boolean;{$IFDEF USE_INLINE}inline;{$ENDIF}overload;
@@ -209,27 +215,31 @@ Var
int64Val : Int64; int64Val : Int64;
begin begin
pinf := GetPropInfo(FParent,AName); pinf := GetPropInfo(FParent,AName);
If Assigned(pinf) And Assigned(pinf^.SetProc) Then Begin if Assigned(pinf) then begin
Case pinf^.PropType^.Kind of if Assigned(pinf^.SetProc) then begin
tkLString Case pinf^.PropType^.Kind of
{$IFDEF WST_DELPHI},tkString{$ENDIF} tkLString
{$IFDEF FPC},tkSString,tkAString{$ENDIF} {$IFDEF WST_DELPHI},tkString{$ENDIF}
{$IFDEF WST_UNICODESTRING},tkUString{$ENDIF} {$IFDEF FPC},tkSString,tkAString{$ENDIF}
,tkWString : {$IFDEF WST_UNICODESTRING},tkUString{$ENDIF}
SetStrProp(FParent,pinf,AValue); ,tkWString :
tkEnumeration : SetStrProp(FParent,pinf,AValue);
SetEnumProp(FParent,pinf,AValue); tkEnumeration :
tkInteger,tkInt64{$IFDEF FPC},tkQWord{$ENDIF} : SetEnumProp(FParent,pinf,AValue);
Begin tkInteger,tkInt64{$IFDEF FPC},tkQWord{$ENDIF} :
If TryStrToInt64(AValue,int64Val) Then Begin
SetOrdProp(FParent,AName,int64Val); If TryStrToInt64(AValue,int64Val) Then
End; SetOrdProp(FParent,AName,int64Val);
{$IFDEF FPC} End;
tkBool : {$IFDEF FPC}
SetOrdProp(FParent,AName,Ord(StrToBool(AValue))); tkBool :
{$ENDIF} SetOrdProp(FParent,AName,Ord(StrToBool(AValue)));
End; {$ENDIF}
End; End;
end;
end else if FHandleUnknownProps then begin
FUnknownProps.SetProperty(AName,AValue);
end;
end; end;
procedure TPublishedPropertyManager.SetProperties(const APropsStr: string); procedure TPublishedPropertyManager.SetProperties(const APropsStr: string);
@@ -257,20 +267,24 @@ Var
begin begin
Result := ''; Result := '';
pinf := GetPropInfo(FParent,AName); pinf := GetPropInfo(FParent,AName);
If Assigned(pinf) And Assigned(pinf^.SetProc) Then Begin if Assigned(pinf) then begin
Case pinf^.PropType^.Kind of if Assigned(pinf^.SetProc) then begin
tkLString Case pinf^.PropType^.Kind of
{$IFDEF WST_DELPHI},tkString{$ENDIF} tkLString
{$IFDEF FPC},tkSString,tkAString{$ENDIF} {$IFDEF WST_DELPHI},tkString{$ENDIF}
{$IFDEF WST_UNICODESTRING},tkUString{$ENDIF} {$IFDEF FPC},tkSString,tkAString{$ENDIF}
,tkWString : {$IFDEF WST_UNICODESTRING},tkUString{$ENDIF}
Result := GetStrProp(FParent,pinf); ,tkWString :
tkEnumeration : Result := GetStrProp(FParent,pinf);
Result := GetEnumProp(FParent,pinf); tkEnumeration :
tkInteger,tkInt64{$IFDEF FPC},tkQWord{$ENDIF} : Result := GetEnumProp(FParent,pinf);
Result := IntToStr(GetOrdProp(FParent,pinf)); tkInteger,tkInt64{$IFDEF FPC},tkQWord{$ENDIF} :
End; Result := IntToStr(GetOrdProp(FParent,pinf));
End; End;
end;
end else if FHandleUnknownProps then begin
Result := FUnknownProps.GetProperty(AName);
end;
end; end;
function TPublishedPropertyManager.GetPropertyNames(ADest: TStrings): Integer; function TPublishedPropertyManager.GetPropertyNames(ADest: TStrings): Integer;
@@ -279,6 +293,8 @@ Var
i, propListLen : Integer; i, propListLen : Integer;
begin begin
ADest.Clear(); ADest.Clear();
if FHandleUnknownProps then
FUnknownProps.GetPropertyNames(ADest);
propListLen := GetPropList(PTypeInfo(FParent.ClassInfo),propList); propListLen := GetPropList(PTypeInfo(FParent.ClassInfo),propList);
if (propListLen > 0) then begin if (propListLen > 0) then begin
Try Try
@@ -329,10 +345,16 @@ begin
End; End;
end; end;
constructor TPublishedPropertyManager.Create(AParent: TObject); constructor TPublishedPropertyManager.Create(
AParent : TObject;
const AHandleUnknownProps : Boolean = False
);
begin begin
Assert(Assigned(AParent)); Assert(Assigned(AParent));
FParent := AParent; FParent := AParent;
FHandleUnknownProps := AHandleUnknownProps;
if FHandleUnknownProps then
FUnknownProps := TStoredPropertyManager.Create() as IPropertyManager;
end; end;