Commit 3d5c2943 authored by Mark van Renswoude's avatar Mark van Renswoude

Added support for changing string properties to enumerations

parent 17043551
......@@ -48,7 +48,6 @@ object MainForm: TMainForm
Anchors = [akLeft, akTop, akBottom]
Caption = ' Output '
TabOrder = 1
ExplicitHeight = 204
DesignSize = (
422
225)
......@@ -83,6 +82,10 @@ object MainForm: TMainForm
TabOrder = 2
object spFile: TTabSheet
TabVisible = False
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object lblFile: TLabel
Left = 4
Top = 7
......@@ -188,7 +191,6 @@ object MainForm: TMainForm
Default = True
TabOrder = 3
OnClick = btnGenerateClick
ExplicitTop = 258
end
object btnClose: TButton
Left = 355
......@@ -200,7 +202,6 @@ object MainForm: TMainForm
Caption = '&Close'
TabOrder = 4
OnClick = btnCloseClick
ExplicitTop = 258
end
object btnHints: TButton
Left = 7
......@@ -212,7 +213,6 @@ object MainForm: TMainForm
Caption = 'Generate blank &Hints file'
TabOrder = 2
OnClick = btnHintsClick
ExplicitTop = 258
end
object DefaultEditStyle: TcxDefaultEditStyleController
Style.HotTrack = False
......
......@@ -80,6 +80,7 @@ uses
FileCtrl,
SysUtils,
Windows,
Generics.Collections,
MSXMLDOM,
MSXML2_TLB,
......@@ -409,37 +410,98 @@ end;
procedure THintsDelphiXMLDataBindingGenerator.ProcessEnumerations;
procedure ProcessEnumeration(ABindingEnumeration: TXMLDataBindingEnumeration; AHintEnumeration: IXMLEnumeration);
var
hintMemberIndex: Integer;
memberName: String;
memberIndex: Integer;
begin
for hintMemberIndex := 0 to Pred(AHintEnumeration.Count) do
begin
memberName := AHintEnumeration.Member[hintMemberIndex].Name;
for memberIndex := 0 to Pred(ABindingEnumeration.MemberCount) do
begin
if ABindingEnumeration.Members[memberIndex].Name = memberName then
begin
ABindingEnumeration.Members[memberIndex].TranslatedName := AHintEnumeration[hintMemberIndex].Text;
Break;
end;
end;
end;
end;
function GetNewMembers(ABindingEnumeration: TXMLDataBindingEnumeration; AHintEnumeration: IXMLEnumeration): TList<TXMLDataBindingEnumerationMember>;
var
hintMemberIndex: Integer;
member: TXMLDataBindingEnumerationMember;
begin
Result := TList<TXMLDataBindingEnumerationMember>.Create;
for hintMemberIndex := 0 to Pred(AHintEnumeration.Count) do
begin
member := TXMLDataBindingEnumerationMember.Create(Self, ABindingEnumeration, AHintEnumeration[hintMemberIndex].Name);
member.TranslatedName := AHintEnumeration[hintMemberIndex].Text;
Result.Add(member);
end;
end;
var
itemIndex: Integer;
enumeration: IXMLEnumeration;
schemaItem: TXMLDataBindingItem;
enumerationItem: TXMLDataBindingEnumeration;
hintMemberIndex: Integer;
memberName: String;
memberIndex: Integer;
propertyItem: TXMLDataBindingSimpleProperty;
newMembers: TList<TXMLDataBindingEnumerationMember>;
newPropertyItem: TXMLDataBindingItemProperty;
begin
for itemIndex := 0 to Pred(Hints.Enumerations.Count) do
begin
enumeration := Hints.Enumerations[itemIndex];
if FindNode(enumeration.Schema, enumeration.XPath, schemaItem) and
(schemaItem.ItemType = itEnumeration) then
if FindNode(enumeration.Schema, enumeration.XPath, schemaItem) then
begin
enumerationItem := TXMLDataBindingEnumeration(schemaItem);
case schemaItem.ItemType of
itEnumeration:
begin
enumerationItem := TXMLDataBindingEnumeration(schemaItem);
for hintMemberIndex := 0 to Pred(enumeration.Count) do
begin
memberName := enumeration.Member[hintMemberIndex].Name;
if enumeration.HasReplaceMembers and enumeration.ReplaceMembers then
begin
newMembers := GetNewMembers(enumerationItem, enumeration);
try
enumerationItem.ReplaceMembers(newMembers);
finally
FreeAndNil(newMembers);
end;
end else
ProcessEnumeration(TXMLDataBindingEnumeration(schemaItem), enumeration);
end;
for memberIndex := 0 to Pred(enumerationItem.MemberCount) do
begin
if enumerationItem.Members[memberIndex].Name = memberName then
itProperty:
if TXMLDataBindingProperty(schemaItem).PropertyType = ptSimple then
begin
enumerationItem.Members[memberIndex].TranslatedName := enumeration[hintMemberIndex].Text;
Break;
propertyItem := TXMLDataBindingSimpleProperty(schemaItem);
if propertyItem.DataType.Name = 'string' then
begin
enumerationItem := TXMLDataBindingEnumeration.Create(Self, schemaItem.SchemaItem, nil, schemaItem.Name);
newPropertyItem := TXMLDataBindingItemProperty.Create(Self, propertyItem.SchemaItem, propertyItem.Name, enumerationItem);
newMembers := GetNewMembers(enumerationItem, enumeration);
try
enumerationItem.ReplaceMembers(newMembers);
ReplaceItem(schemaItem, newPropertyItem, False);
finally
FreeAndNil(newMembers);
end;
end;
end;
end;
end;
end;
end;
......
This diff is collapsed.
......@@ -77,7 +77,7 @@ type
function FindInterface(ASchema: TXMLDataBindingSchema; const AName: String; AType: TXMLDataBindingInterfaceType): TXMLDataBindingInterface;
function FindEnumeration(ASchema: TXMLDataBindingSchema; const AName: String): TXMLDataBindingEnumeration;
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
procedure ResolveSchema(ASchema: TXMLDataBindingSchema);
procedure ResolveAlias(ASchema: TXMLDataBindingSchema);
......@@ -113,7 +113,7 @@ type
private
FOwner: TXMLDataBindingGenerator;
protected
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem); virtual;
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); virtual;
property Owner: TXMLDataBindingGenerator read FOwner;
public
......@@ -136,7 +136,7 @@ type
function GetIncludes(Index: Integer): TXMLDataBindingSchema;
function GetTargetNamespace: String;
protected
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem); override;
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
procedure AddInclude(ASchema: TXMLDataBindingSchema);
procedure AddItem(AItem: TXMLDataBindingItem);
......@@ -177,12 +177,11 @@ type
protected
function GetItemType: TXMLDataBindingItemType; virtual; abstract;
procedure SetName(const Value: String);
property SchemaItem: IXMLSchemaItem read FSchemaItem;
public
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String);
property Schema: TXMLDataBindingSchema read FSchema write FSchema;
property SchemaItem: IXMLSchemaItem read FSchemaItem;
property TargetNamespace: String read FTargetNamespace write FTargetNamespace;
property DocumentElement: Boolean read FDocumentElement write FDocumentElement;
......@@ -211,7 +210,7 @@ type
protected
function GetItemType: TXMLDataBindingItemType; override;
procedure ReplaceItem(const AOldItem: TXMLDataBindingItem; const ANewItem: TXMLDataBindingItem); override;
procedure ReplaceItem(const AOldItem: TXMLDataBindingItem; const ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
procedure AddProperty(AProperty: TXMLDataBindingProperty);
public
......@@ -251,9 +250,11 @@ type
protected
function GetItemType: TXMLDataBindingItemType; override;
public
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; AEnumerations: IXMLEnumerationCollection; const AName: String);
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; AEnumerations: IXMLEnumerationCollection; const AName: String); overload;
destructor Destroy; override;
procedure ReplaceMembers(AMembers: TEnumerable<TXMLDataBindingEnumerationMember>);
property MemberCount: Integer read GetMemberCount;
property Members[Index: Integer]: TXMLDataBindingEnumerationMember read GetMembers;
end;
......@@ -309,7 +310,7 @@ type
function GetIsReadOnly: Boolean; override;
function GetPropertyType: TXMLDataBindingPropertyType; override;
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem); override;
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
public
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String; AItem: TXMLDataBindingItem);
......@@ -335,7 +336,7 @@ type
protected
function GetItemType: TXMLDataBindingItemType; override;
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem); override;
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
public
property Item: TXMLDataBindingItem read FItem write FItem;
end;
......@@ -1233,13 +1234,13 @@ begin
end;
procedure TXMLDataBindingGenerator.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
procedure TXMLDataBindingGenerator.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
var
schemaIndex: Integer;
begin
for schemaIndex := Pred(SchemaCount) downto 0 do
Schemas[schemaIndex].ReplaceItem(AOldItem, ANewItem);
Schemas[schemaIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
end;
......@@ -1304,7 +1305,7 @@ begin
interfaceItem.BaseName := complexAliasItem.Item.Name;
ASchema.AddItem(interfaceItem);
ReplaceItem(complexAliasItem, interfaceItem);
ReplaceItem(complexAliasItem, interfaceItem, True);
FreeAndNil(complexAliasItem);
end;
end;
......@@ -1314,7 +1315,7 @@ begin
{ Remove the alias element - TXMLDataBindingInterfaceItem.ReplaceItem
will take care of fixing it's properties. }
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem(item);
ReplaceItem(simpleAliasItem, nil);
ReplaceItem(simpleAliasItem, nil, True);
FreeAndNil(simpleAliasItem);
end;
end;
......@@ -1353,7 +1354,7 @@ begin
end;
if Assigned(referenceItem) then
ReplaceItem(AItem, referenceItem)
ReplaceItem(AItem, referenceItem, True)
else
raise EXMLDataBindingUnresolvedItem.CreateFmt('Unresolved %s: %s',
[GetEnumName(TypeInfo(TXMLDataBindingInterfaceType), Ord(AItem.InterfaceType)),
......@@ -1639,7 +1640,7 @@ begin
end;
procedure TXMLDataBindingGeneratorItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
procedure TXMLDataBindingGeneratorItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
begin
end;
......@@ -1663,7 +1664,7 @@ begin
end;
procedure TXMLDataBindingSchema.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
procedure TXMLDataBindingSchema.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
var
itemIndex: Integer;
......@@ -1672,9 +1673,13 @@ begin
for itemIndex := Pred(ItemCount) downto 0 do
if Items[itemIndex] = AOldItem then
FItems.Extract(AOldItem)
else
Items[itemIndex].ReplaceItem(AOldItem, ANewItem);
begin
if ARemoveOnly then
FItems.Extract(AOldItem)
else
FItems[itemIndex] := ANewItem;
end else
Items[itemIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
end;
......@@ -1829,7 +1834,7 @@ begin
end;
procedure TXMLDataBindingInterface.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
procedure TXMLDataBindingInterface.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
var
propertyIndex: Integer;
propertyItem: TXMLDataBindingProperty;
......@@ -1846,8 +1851,12 @@ begin
propertyItem := Properties[propertyIndex];
if propertyItem = AOldItem then
FProperties.Extract(propertyItem)
else
begin
if ARemoveOnly then
FProperties.Extract(propertyItem)
else
FProperties[propertyIndex] := ANewItem as TXMLDataBindingProperty;
end else
begin
if (AOldItem.ItemType = itSimpleTypeAlias) and
(propertyItem.PropertyType = ptItem) then
......@@ -1862,9 +1871,9 @@ begin
{ FProperties owns itemProperty and will free it }
FProperties[propertyIndex] := simpleProperty;
end else
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem);
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
end else
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem);
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
end;
end;
end;
......@@ -1961,8 +1970,11 @@ begin
FMembers := TObjectList<TXMLDataBindingEnumerationMember>.Create;
for memberIndex := 0 to Pred(AEnumerations.Count) do
FMembers.Add(TXMLDataBindingEnumerationMember.Create(Owner, Self, AEnumerations.Items[memberIndex].Value));
if Assigned(AEnumerations) then
begin
for memberIndex := 0 to Pred(AEnumerations.Count) do
FMembers.Add(TXMLDataBindingEnumerationMember.Create(Owner, Self, AEnumerations.Items[memberIndex].Value));
end;
end;
......@@ -1974,6 +1986,18 @@ begin
end;
procedure TXMLDataBindingEnumeration.ReplaceMembers(AMembers: TEnumerable<TXMLDataBindingEnumerationMember>);
var
member: TXMLDataBindingEnumerationMember;
begin
FMembers.Clear;
for member in AMembers do
FMembers.Add(member);
end;
function TXMLDataBindingEnumeration.GetItemType: TXMLDataBindingItemType;
begin
Result := itEnumeration;
......@@ -2048,7 +2072,7 @@ begin
end;
procedure TXMLDataBindingItemProperty.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
procedure TXMLDataBindingItemProperty.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
begin
inherited;
......@@ -2085,7 +2109,7 @@ end;
{ TXMLDataBindingComplexTypeAliasItem }
procedure TXMLDataBindingComplexTypeAliasItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
procedure TXMLDataBindingComplexTypeAliasItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
begin
inherited;
......
......@@ -59,6 +59,7 @@
<VerInfo_Locale>1033</VerInfo_Locale>
<UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
<UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
......@@ -68,6 +69,7 @@
<VerInfo_Locale>1033</VerInfo_Locale>
<UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
<UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<Version>7.0</Version>
......@@ -80,9 +82,14 @@
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<BT_BuildType>Debug</BT_BuildType>
<Debugger_RunParams>&quot;P:\sam\xsd\MBCPOS\masterupdatefile_v_2_7.xsd&quot;</Debugger_RunParams>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
......@@ -125,6 +132,10 @@
<Source>
<Source Name="MainSource">X2XMLDataBinding.dpr</Source>
</Source>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k250.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp250.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Platforms>
<Platform value="Win32">True</Platform>
......
No preview for this file type
[Stats]
EditorSecs=37
DesignerSecs=5
EditorSecs=92
DesignerSecs=13
InspectorSecs=1
CompileSecs=620
OtherSecs=5
CompileSecs=1741
OtherSecs=40
StartTime=09/04/2020 10:52:32
RealKeys=0
EffectiveKeys=0
DebugSecs=20
DebugSecs=71
......@@ -25,6 +25,7 @@
</xs:sequence>
<xs:attribute name="Schema" type="xs:string" use="required"/>
<xs:attribute name="XPath" type="xs:string" use="required"/>
<xs:attribute name="ReplaceMembers" type="xs:boolean" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment