Even so:
This Assign() method does not need to use a variant, but can still offer
the same functionality as it does now. It just means that the method
needs to determine the actual type itself...

tiOPF has done a lot to get rid of using variants and it isn't used
that much anymore.  If there is anything else we can do to get rid of
the last few cases, we would.
Below is one of the methods used in the Assign method.  GetPropValue
and SetPropValue returns/uses Variant, so how would you do it
otherwise using RTTI?
eg: Query PropInfo and call the individual methods (GetOrdProp,
GetStrProp, etc.) based on PropInfo.Kind in a case statement?

const
 // All string type properties
 ctkString = [ tkChar, tkString, tkWChar, tkLString, tkWString
                       {$IFDEF FPC},tkAString{$ENDIF} ] ;
 // Integer type properties
 ctkInt    = [ tkInteger, tkInt64 ] ;
 // Float type properties
 ctkFloat  = [ tkFloat ] ;
 // Numeric type properties
 ctkNumeric = [tkInteger, tkInt64, tkFloat];
 // All simple types (string, int, float)
 ctkSimple = ctkString + ctkInt + ctkFloat ;

procedure TtiObject.AssignPublishedProp( pSource : TtiObject ;
psPropName : string) ;
var
 lPropType: TTypeKind;
 lPropValue: Variant;
begin
 lPropType := TypInfo.PropType( pSource, psPropName ) ;
 if lPropType in ctkSimple + [tkVariant, tkEnumeration] then
 begin
   { Graeme 2006-05-16: Passing in False, as a workaround for a FPC bug. }
   lPropValue := TypInfo.GetPropValue(pSource, psPropName, False);
   TypInfo.SetPropValue( Self, psPropName, lPropValue);
 end
 else
   raise EtiOPFProgrammerException.CreateFmt(cErrorSettingProperty,
     [ClassName, psPropName, 'Unknown property type']);
end ;


Variants are for (excuse me the term) lazy coders...

I've heard that before.. :-)

Graeme.


--
There's no place like 127.0.0.1
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to