Delphi-Quellcode:
for linePath in TempMenuData do
begin
if (MenuLevel = 1)
and (TempMenuData.Strings[TempMenuData.IndexOf(linePath)].Contains('object')
and TempMenuData.Strings[TempMenuData.IndexOf(linePath)].Contains('TMenuItem'))
then
begin
tempMenuTop := TempMenuData.Strings[TempMenuData.IndexOf(linePath)];
tempMenuTop := tempMenuTop.Replace(' ', EmptyStr);
tempMenuTop := tempMenuTop.Replace('object', EmptyStr);
tempMenuTop := tempMenuTop.Replace(':TMenuItem', EmptyStr);
MenuLevel := 2;
end
else if (MenuLevel = 2)
and (TempMenuData.Strings[TempMenuData.IndexOf(linePath)].Contains('object')
and TempMenuData.Strings[TempMenuData.IndexOf(linePath)].Contains('TMenuItem'))
then
begin
tempPath := tempMenuTop + '->' + TempMenuData.Strings[TempMenuData.IndexOf(linePath)];
tempPath := tempPath.Replace(' ', EmptyStr);
tempPath := tempPath.Replace('object', EmptyStr);
tempPath := tempPath.Replace(':TMenuItem', EmptyStr);
if TempMenuData.Strings[TempMenuData.IndexOf(linePath)+1].Contains('Action') then
begin
tempMenuAction := TempMenuData.Strings[TempMenuData.IndexOf(linePath)+1];
tempMenuAction := tempMenuAction.Replace('Action = ', '');
tempMenuAction := tempMenuAction.Replace(' ', '');
end;
MenuLevel := 3;
end
else if (MenuLevel = 3)
and (TempMenuData.Strings[TempMenuData.IndexOf(linePath)].Contains('object')
and TempMenuData.Strings[TempMenuData.IndexOf(linePath)].Contains('TMenuItem'))
then
begin
tempPath := tempPath + '->' + TempMenuData.Strings[TempMenuData.IndexOf(linePath)];
tempPath := tempPath.Replace(' ', EmptyStr);
tempPath := tempPath.Replace('object', EmptyStr);
tempPath := tempPath.Replace(':TMenuItem', EmptyStr);
if TempMenuData.Strings[TempMenuData.IndexOf(linePath)+1].Contains('Action') then
begin
tempMenuAction := TempMenuData.Strings[TempMenuData.IndexOf(linePath)+1];
tempMenuAction := tempMenuAction.Replace('Action = ', '');
tempMenuAction := tempMenuAction.Replace(' ', '');
end;
end;
if not linePath.Contains('end') then
begin
for lineNewPath in FinishedTable do
begin
if FinishedTable[FinishedTable.IndexOf(lineNewPath)].Contains(tempMenuAction)
and not FinishedTable[FinishedFile.IndexOf(lineNewPath)].Contains('Path')
then
begin
FinishedTable.Strings[FinishedTable.IndexOf(lineNewPath)]
:= FinishedTable.Strings[FinishedTable.IndexOf(lineNewPath)] +
' Path: ' + tempPath;
break;
end;
end;
end
else if linePath.Contains('end') then
begin
MenuLevel := MenuLevel-1;
end;
if MenuLevel = 0 then
begin
tempPath := EmptyStr;
end;
end;
So solltest du bei Parsern aber nicht arbeiten. StringReplace ist sehr unsicher, da du den Kontext nicht beachtest. Das kann in einigen Fällen zu unbeabsichtigten Ergebnissen oder sogar Fehlern führen. Wieso benutzt du nicht einfach TParser? Da brauchst du dir um all das keine Gedanken zu machen, und außerdem ist ein andauerndes Aufrufen von StringReplace auch nicht gerade performant.