|
From: <fas...@us...> - 2006-12-10 05:19:13
|
Revision: 736
http://svn.sourceforge.net/instantobjects/revision/?rev=736&view=rev
Author: fastbike2
Date: 2006-12-09 21:19:12 -0800 (Sat, 09 Dec 2006)
Log Message:
-----------
Refactored InstantAttributeEditor form to remove exceptions from flow control
Parallel changes made to Model Maker object foundry plugin expert.
Modified Paths:
--------------
trunk/Source/Design/InstantAttributeEditor.pas
trunk/Source/ObjectFoundry/OFExpert.pas
Modified: trunk/Source/Design/InstantAttributeEditor.pas
===================================================================
--- trunk/Source/Design/InstantAttributeEditor.pas 2006-12-08 09:41:29 UTC (rev 735)
+++ trunk/Source/Design/InstantAttributeEditor.pas 2006-12-10 05:19:12 UTC (rev 736)
@@ -61,12 +61,14 @@
private
FAttribute: TInstantCodeAttribute;
FInterface: IInterface;
+ FErrorMsg: string;
protected
property Attribute: TInstantCodeAttribute read FAttribute;
property MMInterface: IInterface read FInterface;
+ property ErrorMsg: string read FErrorMsg write FErrorMsg;
public
constructor Create(AnAttribute: TInstantCodeAttribute; const AInterface: IInterface);
- procedure Validate; virtual;
+ function Validate: Boolean; virtual;
end;
TInstantAttributeEditorForm = class(TInstantEditForm)
@@ -412,13 +414,13 @@
if OKButton.CanFocus then
OKButton.SetFocus;
- try
- FValidator.Validate;
- except
+ if not FValidator.Validate then
+ begin
ModalResult := mrNone;
PageControl.ActivePage := DefinitionSheet;
NameEdit.SetFocus;
- raise;
+ MessageDlg(FValidator.ErrorMsg, mtError, [mbOK], 0);
+ Abort;
end;
if (Subject.AttributeType = atString) and (Subject.Metadata.Size = 0) then
@@ -427,7 +429,7 @@
ModalResult := mrNone;
PageControl.ActivePage := DefinitionSheet;
SizeEdit.SetFocus;
- Abort;
+ Exit;
end;
if ObjectClassEdit.Enabled then
@@ -782,7 +784,7 @@
FInterface := AInterface;
end;
-procedure TInstantAttributeValidator.Validate;
+function TInstantAttributeValidator.Validate: Boolean;
var
TempAttribute: TInstantCodeAttribute;
CodeClass: TInstantCodeClass;
@@ -797,45 +799,85 @@
for J := 0 to Pred(CurrentClass.SubClassCount) do
begin
for K := 0 to Pred(CurrentClass.SubClasses[J].PropertyCount) do
+ begin
+ if not Result then
+ Break;
if SameText(CurrentClass.SubClasses[J].Properties[K].Name, FAttribute.Name) then
- raise Exception.CreateFmt('Attribute "%s" exists in descendant class "%s"',
+ begin
+ ErrorMsg := Format('Attribute "%s" exists in descendant class "%s"',
[FAttribute.Name, CurrentClass.SubClasses[J].Name]);
+ Result := False;
+ end;
+ end;
for K := 0 to Pred(CurrentClass.SubClasses[J].MethodCount) do
+ begin
+ if not Result then
+ Break;
if SameText(CurrentClass.SubClasses[J].Methods[K].Name, FAttribute.Name) then
- raise Exception.CreateFmt('Attribute "%s" exists as a method in descendant class "%s"',
+ begin
+ ErrorMsg := Format('Attribute "%s" exists as a method in descendant class "%s"',
[FAttribute.Name, CurrentClass.SubClasses[J].Name]);
+ Result := False;
+ end;
+ end;
CheckChildClass(CurrentClass.SubClasses[J]);
end;
end;
begin
+ Result := True;
+ ErrorMsg := '';
+
if not Assigned(FAttribute) and not Assigned(FAttribute.Owner)
and not Assigned(FAttribute.Owner.Owner) then
- raise Exception.Create('Cannot validate attribute');
-
+ begin
+ ErrorMsg := 'Cannot validate attribute';
+ Result := False;
+ Exit;
+ end;
// check that the same attribute name is not used in an ancestor class
CodeClass := FAttribute.Owner.Owner.BaseClass;
- while (CodeClass <> nil) do
+ while (Result) and (CodeClass <> nil) do
begin
for I := 0 to Pred(CodeClass.PropertyCount) do
+ begin
+ if not Result then
+ Break;
if SameText(CodeClass.Properties[I].Name, FAttribute.Name) then
- raise Exception.CreateFmt('Attribute "%s" exists in ancestor class "%s"',
- [FAttribute.Name, CodeClass.Name]);
+ begin
+ ErrorMsg := Format('Attribute "%s" exists in ancestor class "%s"',
+ [FAttribute.Name, CodeClass.Name]);
+ Result := False;
+ end;
+ end;
for I := 0 to Pred(CodeClass.MethodCount) do
+ begin
+ if not Result then
+ Break;
if SameText(CodeClass.Methods[I].Name, FAttribute.Name) then
- raise Exception.CreateFmt('Attribute "%s" exists as a method in ancestor class "%s"',
+ begin
+ ErrorMsg := Format('Attribute "%s" exists as a method in ancestor class "%s"',
[FAttribute.Name, CodeClass.Name]);
+ Result := False;
+ end;
+ end;
CodeClass := CodeClass.BaseClass;
end;
// check that the same attribute name is not used in any child class
- CheckChildClass(FAttribute.Owner.Owner);
+ if Result then
+ CheckChildClass(FAttribute.Owner.Owner);
- if Assigned(FAttribute.Owner) then
+ if Result and Assigned(FAttribute.Owner) then
for I := 0 to Pred(FAttribute.Owner.AttributeCount) do
begin
+ if not Result then
+ Break;
TempAttribute := FAttribute.Owner.Attributes[I];
if (TempAttribute <> FAttribute) and SameText(TempAttribute.Name, FAttribute.Name) then
- raise Exception.Create('Attribute Name already used');
+ begin
+ ErrorMsg := 'Attribute Name already used';
+ Result := False;
+ end;
end;
end;
Modified: trunk/Source/ObjectFoundry/OFExpert.pas
===================================================================
--- trunk/Source/ObjectFoundry/OFExpert.pas 2006-12-08 09:41:29 UTC (rev 735)
+++ trunk/Source/ObjectFoundry/OFExpert.pas 2006-12-10 05:19:12 UTC (rev 736)
@@ -103,7 +103,7 @@
type
TMMAttributeValidator = class(TInstantAttributeValidator)
public
- procedure Validate; override;
+ function Validate: Boolean; override;
end;
@@ -604,7 +604,7 @@
{ TMMAttributeValidator }
-procedure TMMAttributeValidator.Validate;
+function TMMAttributeValidator.Validate: Boolean;
var
MMProperty: IMMProperty;
CodeClass: IMMClassifier;
@@ -618,14 +618,22 @@
Exit;
for J := 0 to Pred(CurrentClass.DescendantCount) do
begin
+ if not Result then
+ Break;
if CurrentClass.Descendants[J].FindMember(Attribute.Name, I) then
- raise Exception.CreateFmt('Attribute "%s" exists in descendant class "%s"',
+ begin
+ ErrorMsg := Format('Attribute "%s" exists in descendant class "%s"',
[Attribute.Name, CurrentClass.Descendants[J].Name]);
+ Result := False;
+ end;
CheckChildClass(CurrentClass.Descendants[J]);
end;
end;
begin
+ Result := True;
+ ErrorMsg := '';
+
if MMInterface = nil then
Exit;
MMProperty := MMInterface as IMMProperty;
@@ -638,19 +646,26 @@
// check that the new attribute name is not used in parent class
// except by itself
if CodeClass.FindMember(Attribute.Name, I) and
- (CodeClass.Members[I] <> MMProperty) then
- raise Exception.Create('Attribute Name already used');
+ (CodeClass.Members[I] <> MMProperty) then
+ begin
+ ErrorMsg := 'Attribute Name already used';
+ Result := False;
+ end;
// check that the new attribute name is not used in any child class
- CheckChildClass(CodeClass);
+ if Result then
+ CheckChildClass(CodeClass);
// check that the new attribute name is not used in an ancestor class
CodeClass := CodeClass.Ancestor;
- while (CodeClass <> nil) do
+ while Result and (CodeClass <> nil) do
begin
if CodeClass.FindMember(Attribute.Name, I) then
- raise Exception.CreateFmt('Attribute "%s" exists in ancestor class "%s"',
+ begin
+ ErrorMsg := Format('Attribute "%s" exists in ancestor class "%s"',
[Attribute.Name, CodeClass.Name]);
+ Result := False;
+ end;
CodeClass := CodeClass.Ancestor;
end;
end;
|