From: <wp...@us...> - 2009-12-19 16:27:27
|
Revision: 878 http://instantobjects.svn.sourceforge.net/instantobjects/revision/?rev=878&view=rev Author: wp2udk Date: 2009-12-19 16:27:18 +0000 (Sat, 19 Dec 2009) Log Message: ----------- Delphi 2010 Extension: When including Custom Attributes in an IO Model the code parser failed and you got a message saying that Txxx class was not registered when running the application. The fix simply moves the parser beyond the Custom Attributes. This is not a specific implementation for D2010 (no compiler directives are included). It should compile into older versions of D2010 without any problems. If you are using a Delphi version prior to D2010 the IDE will simply throw a Syntax error if you try to use Custom Attributes. A code example: TAddress = class(TInstantObject) {IOMETADATA City: String(30); PostalCode: String(8); Street: String(30); } [MyAttr('x')] <--- D2010 Custom Attribute _City: TInstantString; _PostalCode: TInstantString; _Street: TInstantString; private [MyAttr('x')] <--- D2010 Custom Attribute function GetCity: string; function GetPostalCode: string; function GetStreet: string; procedure SetCity(const Value: string); procedure SetPostalCode(const Value: string); procedure SetStreet(const Value: string); published property City: string read GetCity write SetCity; property PostalCode: string read GetPostalCode write SetPostalCode; property Street: string read GetStreet write SetStreet; end; Modified Paths: -------------- trunk/Source/Core/InstantCode.pas Modified: trunk/Source/Core/InstantCode.pas =================================================================== --- trunk/Source/Core/InstantCode.pas 2009-10-14 05:53:23 UTC (rev 877) +++ trunk/Source/Core/InstantCode.pas 2009-12-19 16:27:18 UTC (rev 878) @@ -495,6 +495,12 @@ TInstantCodeContainerMethodFlag = (mfIndex, mfValue, mfResult); TInstantCodeContainerMethodFlags = set of TInstantCodeContainerMethodFlag; + TInstantCodeRttiAttribute = class(TInstantCodeMember) + protected + class function InternalAtInstance(Reader: TInstantCodeReader; out Name: string): Boolean; override; + procedure InternalRead(Reader: TInstantCodeReader); override; + end; + TInstantCodeAttributeTailor = class(TObject) private FAddMethod: TInstantCodeMethod; @@ -2858,13 +2864,15 @@ Result := TInstantCodeField.AtInstance(Reader) or TInstantCodeMethod.AtInstance(Reader) or - TInstantCodeProperty.AtInstance(Reader); + TInstantCodeProperty.AtInstance(Reader) or + TInstantCodeRttiAttribute.AtInstance(Reader); end; procedure TInstantCodeMembers.InternalRead(Reader: TInstantCodeReader); begin ReadObjects(Reader, - [TInstantCodeField, TInstantCodeMethod, TInstantCodeProperty]); + [TInstantCodeField, TInstantCodeMethod, TInstantCodeProperty, + TInstantCodeRttiAttribute]); end; procedure TInstantCodeMembers.InternalWrite(Writer: TInstantCodeWriter); @@ -3286,6 +3294,32 @@ FTypeLink.Name := Value; end; +{ TInstantCodeRttiAttribute } + +class function TInstantCodeRttiAttribute.InternalAtInstance( + Reader: TInstantCodeReader; out Name: string): Boolean; +begin + Result := Reader.ReadChar = '['; + if Result then + Name := Reader.ReadToken else + Name := ''; +end; + +procedure TInstantCodeRttiAttribute.InternalRead(Reader: TInstantCodeReader); +var + BracketCount: Integer; + C: Char; +begin + inherited; + + BracketCount := 0; + repeat + C := Reader.ReadChar; + if C = '[' then Inc(BracketCount) else + if C = ']' then Dec(BracketCount); + until BracketCount = 0; +end; + { TInstantCodeAttributeTailor } procedure TInstantCodeAttributeTailor.AddCountProp; @@ -9032,4 +9066,3 @@ DestroyTypeProcessors; end. - |