I have this code:
procedure Settings.Init( webSettings : WebConfigSettings; resolveBracketParameters : Boolean );
var
Count : Integer;
function Substitute( var label : String; isLoginWelcomeLabel : boolean := false ) : boolean;
function GetObserverSingular : String;
begin
if ObserverLabel.ToLower.EndsWith( 's' )
then result := ObserverLabel.Substring( 0, ObserverLabel.Length -1 )
else result := ObserverLabel;
end;
begin
if label = nil then exit false;
var newlabel := label.Replace( webSettings.LabelTags.AtRiskTag, AtRiskLabel )
.Replace( webSettings.LabelTags.BarrierTag, BarrierLabel )
.Replace( webSettings.LabelTags.Category1Tag, Category1Label )
.Replace( webSettings.LabelTags.Category2Tag, Category2Label )
.Replace( webSettings.LabelTags.Category3Tag, Category3Label )
// .Replace( webSettings.LabelTags.CategoryAndSubCategory1Tag, ... ) // not yet
// .Replace( webSettings.LabelTags.CategoryAndSubCategory2Tag, ... ) // not yet
// .Replace( webSettings.LabelTags.CategoryAndSubCategory3Tag, ... ) // not yet
.Replace( webSettings.LabelTags.ObservationTag, ObservationLabel )
.Replace( webSettings.LabelTags.ObserverTag, if isLoginWelcomeLabel then ObserverLabel else GetObserverSingular )
.Replace( webSettings.LabelTags.NoteTag, NoteLabel )
.Replace( webSettings.LabelTags.PointTag, PointLabel )
.Replace( webSettings.LabelTags.SafeTag, SafeLabel )
.Replace( webSettings.LabelTags.SiteNameTag, SiteName )
.Replace( webSettings.LabelTags.SubCategory1Tag, SubCategory1Label )
.Replace( webSettings.LabelTags.SubCategory2Tag, SubCategory2Label )
.Replace( webSettings.LabelTags.SubCategory3Tag, SubCategory3Label )
.Replace( webSettings.LabelTags.UserNameTag, UserNameLabel )
.Replace( webSettings.LabelTags.TemplateTag, TemplateLabel );
newlabel := newlabel.Replace( webSettings.LabelTags.AtRiskTag.ToLower, AtRiskLabel.ToLower )
.Replace( webSettings.LabelTags.BarrierTag.ToLower, BarrierLabel.ToLower )
.Replace( webSettings.LabelTags.Category1Tag.ToLower, Category1Label.ToLower )
.Replace( webSettings.LabelTags.Category2Tag.ToLower, Category2Label.ToLower )
.Replace( webSettings.LabelTags.Category3Tag.ToLower, Category3Label.ToLower )
// .Replace( webSettings.LabelTags.CategoryAndSubCategory1Tag, ... ) // not yet
// .Replace( webSettings.LabelTags.CategoryAndSubCategory2Tag, ... ) // not yet
// .Replace( webSettings.LabelTags.CategoryAndSubCategory3Tag, ... ) // not yet
.Replace( webSettings.LabelTags.ObservationTag.ToLower, ObservationLabel.ToLower )
.Replace( webSettings.LabelTags.ObserverTag.ToLower, if isLoginWelcomeLabel then ObserverLabel.ToLower else GetObserverSingular.ToLower )
.Replace( webSettings.LabelTags.NoteTag.ToLower, NoteLabel.ToLower )
.Replace( webSettings.LabelTags.PointTag.ToLower, PointLabel.ToLower )
.Replace( webSettings.LabelTags.SafeTag.ToLower, SafeLabel.ToLower )
.Replace( webSettings.LabelTags.SiteNameTag, SiteName.ToLower )
.Replace( webSettings.LabelTags.SubCategory1Tag.ToLower, SubCategory1Label.ToLower )
.Replace( webSettings.LabelTags.SubCategory2Tag.ToLower, SubCategory2Label.ToLower )
.Replace( webSettings.LabelTags.SubCategory3Tag.ToLower, SubCategory3Label.ToLower )
.Replace( webSettings.LabelTags.UserNameTag.ToLower, UserNameLabel.ToLower )
.Replace( webSettings.LabelTags.TemplateTag.ToLower, TemplateLabel.ToLower );
result := newlabel <> label;
label := newlabel;
// stop it if it looks like there is an infinite loop going on (one tag could potentially substitute another tag)
inc( Count );
if Count > 10 then exit false;
end;
procedure SubstituteTags;
begin
// mlt
// I'm not sure if my code works right here or not.
// the intent is that all the [key] type parameters get replaced.
// but I'm not sure if it is somehow order dependent.
// it seemed to work, so maybe it is okay, but maybe I just have them in the right order
// gotta move on
Count := 0; while Substitute( var AtRiskLabel ) do;
Count := 0; while Substitute( var AtRiskNotesLabel ) do;
Count := 0; while Substitute( var BarrierLabel ) do;
Count := 0; while Substitute( var BarriersLabel ) do;
Count := 0; while Substitute( var CancelLabel ) do;
Count := 0; while Substitute( var Category1Label ) do;
Count := 0; while Substitute( var Category2Label ) do;
Count := 0; while Substitute( var Category3Label ) do;
Count := 0; while Substitute( var DeleteLabel ) do;
Count := 0; while Substitute( var JobSafetyAnalysisLabel ) do;
Count := 0; while Substitute( var LoginWelcomeLabel , true ) do;
Count := 0; while Substitute( var NoteLabel ) do;
Count := 0; while Substitute( var ObservationLabel ) do;
Count := 0; while Substitute( var ObserverLabel ) do;
Count := 0; while Substitute( var PointCategoryLabel ) do;
Count := 0; while Substitute( var PointLabel ) do;
Count := 0; while Substitute( var SafeLabel ) do;
Count := 0; while Substitute( var SafeNotesLabel ) do;
Count := 0; while Substitute( var SaveLabel ) do;
Count := 0; while Substitute( var SubCategory1Label ) do;
Count := 0; while Substitute( var SubCategory2Label ) do;
Count := 0; while Substitute( var SubCategory3Label ) do;
Count := 0; while Substitute( var TemplateLabel ) do;
Count := 0; while Substitute( var ThoughtOfDayLabel ) do;
Count := 0; while Substitute( var UserNameLabel ) do;
end;
begin
…
SubstituteTags;
end;
And when it first goes into Substitute and gets down to the inc(Count), Count is NIL! The AtRiskLabel is a string. It WAS working until I added the GetObserverSingular local function.
p.s. How do I put in code in this editor so that it doesn’t lose the indentation?