Skip to content

Commit 41c36b3

Browse files
committed
[options] some improvements
1 parent 7e71083 commit 41c36b3

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

Quick.Options.pas

+26-35
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ procedure TOptionsContainer.Save;
425425
fSerializer.Save(fFilename,fSections);
426426
finally
427427
//set last state
428+
Sleep(0);
428429
fFileMonitor.Enabled := laststate;
429430
end;
430431
end
@@ -494,33 +495,28 @@ procedure TOptionsValidator.ValidateObject(aObj : TObject);
494495
attrib : TCustomAttribute;
495496
rvalue : TValue;
496497
begin
497-
ctx := TRttiContext.Create;
498-
try
499-
rtype := ctx.GetType(aObj.ClassInfo);
500-
for rprop in rtype.GetProperties do
498+
rtype := ctx.GetType(aObj.ClassInfo);
499+
for rprop in rtype.GetProperties do
500+
begin
501+
//check only published properties
502+
if rprop.Visibility = TMemberVisibility.mvPublished then
501503
begin
502-
//check only published properties
503-
if rprop.Visibility = TMemberVisibility.mvPublished then
504+
//check validation option attributes
505+
for attrib in rprop.GetAttributes do
504506
begin
505-
//check validation option attributes
506-
for attrib in rprop.GetAttributes do
507-
begin
508-
if attrib is Required then ValidateRequired(aObj,rprop)
509-
else if attrib is StringLength then ValidateStringLength(aObj,rprop,StringLength(attrib))
510-
else if attrib is Range then ValidateRange(aObj,rprop,Range(attrib));
511-
end;
512-
rvalue := rprop.GetValue(aObj);
513-
if not rvalue.IsEmpty then
514-
begin
515-
case rvalue.Kind of
516-
tkClass : ValidateObject(rvalue.AsObject);
517-
tkDynArray : ValidateArray(rvalue);
518-
end;
507+
if attrib is Required then ValidateRequired(aObj,rprop)
508+
else if attrib is StringLength then ValidateStringLength(aObj,rprop,StringLength(attrib))
509+
else if attrib is Range then ValidateRange(aObj,rprop,Range(attrib));
510+
end;
511+
rvalue := rprop.GetValue(aObj);
512+
if not rvalue.IsEmpty then
513+
begin
514+
case rvalue.Kind of
515+
tkClass : ValidateObject(rvalue.AsObject);
516+
tkDynArray : ValidateArray(rvalue);
519517
end;
520518
end;
521519
end;
522-
finally
523-
ctx.Free;
524520
end;
525521
end;
526522

@@ -543,22 +539,17 @@ procedure TOptionsValidator.ValidateArray(aValue : TValue);
543539
itvalue : TValue;
544540
i : Integer;
545541
begin
546-
ctx := TRttiContext.Create;
547-
try
548-
rDynArray := ctx.GetType(aValue.TypeInfo) as TRTTIDynamicArrayType;
549-
for i := 0 to aValue.GetArrayLength - 1 do
542+
rDynArray := ctx.GetType(aValue.TypeInfo) as TRTTIDynamicArrayType;
543+
for i := 0 to aValue.GetArrayLength - 1 do
544+
begin
545+
TValue.Make(PPByte(aValue.GetReferenceToRawData)^ + rDynArray.ElementType.TypeSize * i, rDynArray.ElementType.Handle,itvalue);
546+
if not itvalue.IsEmpty then
550547
begin
551-
TValue.Make(PPByte(aValue.GetReferenceToRawData)^ + rDynArray.ElementType.TypeSize * i, rDynArray.ElementType.Handle,itvalue);
552-
if not itvalue.IsEmpty then
553-
begin
554-
case itvalue.Kind of
555-
tkClass : ValidateObject(itvalue.AsObject);
556-
tkDynArray : ValidateArray(itvalue);
557-
end;
548+
case itvalue.Kind of
549+
tkClass : ValidateObject(itvalue.AsObject);
550+
tkDynArray : ValidateArray(itvalue);
558551
end;
559552
end;
560-
finally
561-
ctx.Free;
562553
end;
563554
end;
564555

0 commit comments

Comments
 (0)