program DfmAnalyzer;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.Classes, System.Generics.Collections,
Vcl.Controls;
var
FileName:
String;
Stream: TFileStream;
Parser: TParser;
Current:
String;
FormName:
String;
Actions: TDictionary<TComponentName, TCaption>;
procedure ParseObject(
const Depth: Byte = 0;
const Item: Boolean = False);
procedure ParseCollection;
begin
Parser.NextToken;
while Parser.Token <> '
>'
do
begin
if Parser.TokenSymbolIs('
item')
then
begin
ParseObject(Succ(Depth), True);
end;
Parser.NextToken;
end;
Parser.NextToken;
end;
var
ComponentName:
String;
ComponentType:
String;
begin
Parser.NextToken;
if not Item
then
begin
ComponentName := Parser.TokenString;
if Depth = 0
then
begin
FormName := ComponentName;
end;
Parser.NextToken;
Parser.NextToken;
ComponentType := Parser.TokenString;
Parser.NextToken;
end;
while not Parser.TokenSymbolIs('
end')
do
begin
if Parser.TokenSymbolIs('
object')
then
begin
ParseObject(Succ(Depth));
end else
begin
if Parser.Token = '
<'
then
begin
ParseCollection;
end else
begin
if not Item
and (ComponentType = '
TAction')
and
(Parser.TokenSymbolIs('
Caption'))
then
begin
Parser.NextToken;
Parser.NextToken;
Actions.Add(ComponentName, Parser.TokenWideString);
end;
end;
end;
Parser.NextToken;
end;
end;
begin
try
ReadLn(FileName);
Stream := TFileStream.Create(FileName, fmOpenRead);
Stream.Seek(0, soBeginning);
Parser := TParser.Create(Stream, TFormatSettings.Invariant);
Actions := TDictionary<TComponentName, TCaption>.Create;
try
ParseObject;
WriteLn('
Formularname: ', FormName);
for Current
in Actions.Keys
do
begin
WriteLn('
Caption von ', Current, '
: ', QuotedStr(Actions[Current]));
end;
finally
Actions.Free;
Parser.Free;
Stream.Free;
ReadLn;
end;
except
on E:
Exception do
WriteLn(E.ClassName, '
: ', E.
Message);
end;
end.