unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, PaxCompilerExplorer, PaxCompiler, StdCtrls, ExtCtrls, ComCtrls, IMPORT_Classes; type TForm1 = class(TForm) Panel1: TPanel; Memo1: TMemo; Button1: TButton; PaxCompiler1: TPaxCompiler; PaxPascalLanguage1: TPaxPascalLanguage; PaxCompilerExplorer1: TPaxCompilerExplorer; TreeView1: TTreeView; procedure Button1Click(Sender: TObject); procedure TreeView1DblClick(Sender: TObject); private { Private declarations } L: TList; public { Public declarations } procedure BuildTree; procedure EnumProc(Id: Integer; Host: Boolean; Kind: TMemberKind; Data: Pointer); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin PaxCompiler1.Reset; PaxCompiler1.RegisterLanguage(PaxPascalLanguage1); PaxCompiler1.AddModule('1', 'Pascal'); PaxCompiler1.AddCode('1', Memo1.Lines.Text); if PaxCompiler1.Compile then begin PaxCompilerExplorer1.RegisterCompiler(PaxCompiler1); BuildTree; end else for I:=0 to PaxCompiler1.ErrorCount - 1 do ShowMessage(PaxCompiler1.ErrorMessage[I]); end; procedure TForm1.BuildTree; var N, N2: TTreeNode; I: Integer; begin L := TList.Create; try TreeView1.Items.Clear; N := TreeView1.Items.Add(nil, 'Used namespaces'); L.Add(N); PaxCompilerExplorer1.EnumMembers(0, true, mkNamespace, EnumProc, N); PaxCompilerExplorer1.EnumMembers(0, false, mkNamespace, EnumProc, N); N := TreeView1.Items.Add(nil, 'Noname namespace'); N2 := TreeView1.Items.AddChild(N, 'Types'); L.Add(N2); PaxCompilerExplorer1.EnumMembers(0, false, mkType, EnumProc, N2); N2 := TreeView1.Items.AddChild(N, 'Procedures'); L.Add(N2); PaxCompilerExplorer1.EnumMembers(0, false, mkProcedure, EnumProc, N2); N2 := TreeView1.Items.AddChild(N, 'Functions'); L.Add(N2); PaxCompilerExplorer1.EnumMembers(0, false, mkFunction, EnumProc, N2); N2 := TreeView1.Items.AddChild(N, 'Constants'); L.Add(N2); PaxCompilerExplorer1.EnumMembers(0, false, mkConst, EnumProc, N2); N2 := TreeView1.Items.AddChild(N, 'Variables'); L.Add(N2); PaxCompilerExplorer1.EnumMembers(0, false, mkVar, EnumProc, N2); finally for I := L.Count - 1 downto 0 do begin N2 := TTreeNode(L[I]); if N2.Count = 0 then N2.Delete; end; L.Free; end; end; procedure TForm1.EnumProc(Id: Integer; Host: Boolean; Kind: TMemberKind; Data: Pointer); var N, N2, N3: TTreeNode; Name: String; TypeName: String; begin N := TTreeNode(Data); Name := PaxCompilerExplorer1.Names[Id]; TypeName := PaxCompilerExplorer1.TypeNames[Id]; with TreeView1.Items do case Kind of mkProcedure, mkFunction, mkConstructor, mkDestructor: begin N2 := AddChildObject(N, Name, TObject(Id)); N3 := AddChild(N2, 'Parameters'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkParam, EnumProc, N3); N3 := AddChild(N2, 'Local variables'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkVar, EnumProc, N3); N3 := AddChild(N2, 'Local constants'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkConst, EnumProc, N3); N3 := AddChild(N2, 'Local types'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkType, EnumProc, N3); N3 := TreeView1.Items.AddChild(N2, 'Nested procedures'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, false, mkProcedure, EnumProc, N3); N3 := TreeView1.Items.AddChild(N2, 'Nested functions'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, false, mkFunction, EnumProc, N3); end; mkParam: AddChildObject(N, Name + ': ' + TypeName, TObject(Id)); mkVar: AddChildObject(N, Name + ': ' + TypeName, TObject(Id)); mkConst: AddChildObject(N, Name + ': ' + TypeName, TObject(Id)); mkField: AddChildObject(N, Name + ': ' + TypeName, TObject(Id)); mkProperty: AddChildObject(N, Name + ': ' + TypeName, TObject(Id)); mkType: begin N2 := AddChildObject(N, Name, TObject(Id)); if PaxCompilerExplorer1.IsRecordType(Id) then begin N3 := AddChild(N2, 'Fields'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkField, EnumProc, N3); end else if PaxCompilerExplorer1.IsClassType(Id) then begin N3 := AddChild(N2, 'Fields'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkField, EnumProc, N3); N3 := AddChild(N2, 'Properties'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkProperty, EnumProc, N3); N3 := TreeView1.Items.AddChild(N2, 'Constructors'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, false, mkConstructor, EnumProc, N3); N3 := TreeView1.Items.AddChild(N2, 'Destructor'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, false, mkDestructor, EnumProc, N3); N3 := TreeView1.Items.AddChild(N2, 'Class procedures'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, false, mkProcedure, EnumProc, N3); N3 := TreeView1.Items.AddChild(N2, 'Class functions'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, false, mkFunction, EnumProc, N3); end; end; mkNamespace: begin N2 := AddChildObject(N, Name, TObject(Id)); N3 := AddChild(N2, 'Constants'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkConst, EnumProc, N3); N3 := AddChild(N2, 'Variables'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkVar, EnumProc, N3); N3 := AddChild(N2, 'Procedures'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkProcedure, EnumProc, N3); N3 := AddChild(N2, 'Types'); L.Add(N3); PaxCompilerExplorer1.EnumMembers(Id, Host, mkType, EnumProc, N3); end; end; end; procedure TForm1.TreeView1DblClick(Sender: TObject); var N: TTreeNode; Id, Position: Integer; S: String; begin N := TTreeView(Sender).Selected; if N = nil then Exit; Id := Integer(N.Data); if Id = 0 then Exit; S := PaxCompilerExplorer1.Names[Id]; Position := PaxCompilerExplorer1.Positions[Id]; if Id <> 0 then with Memo1 do begin SetFocus; SelStart := Position; SelLength := Length(S); end; end; end.