Come ottenere la struttura di un modulo da ToolsAPI in Delphi?
Domanda
Voglio ottenere le informazioni sulla struttura di un modulo (unità di pascal) di ToolsAPI. proprio come la vista struttura del IDE fa.
Le classi, dischi, interfacce, Variabili / Costanti, etc I membri, parametri, ecc.
C'è già un modo semplice ed efficiente per ottenere questi metadati?
Soluzione
magari usando un parser non è così cattiva idea?
Altri suggerimenti
Per quanto ne sappia non v'è alcun modo di ricerca speciale informazioni strutturate per un determinato file.
Che cosa si potrebbe fare è quello di accedere alle informazioni nel riquadro Struttura. In questo modo richiede il file di essere il modulo attivo (può essere raggiunto dal OTA), l'uscita dipende dalle impostazioni del riquadro Struttura (Strumenti | Opzioni ... -> Opzioni Ambiente | Explorer) e se un nodo è un campo, un procedura o qualsiasi altra cosa deve essere determinata nel corso l'indice dell'immagine, genitore ...
Questo codice cammina attraverso il riquadro Struttura.
procedure StructureViewToSL(ASL: TStringList);
procedure TreeToSL(ANode: IOTAStructureNode; ASL: TStringList; const APrefix: string);
var
I: Integer;
begin
ASL.Add(APrefix + ANode.Caption);
for I := 0 to ANode.ChildCount - 1 do
TreeToSL(ANode.Child[I], ASL, APrefix + ' ');
end;
var
StructureView: IOTAStructureView;
StructureContext: IOTAStructureContext;
Node: IOTAStructureNode;
I: Integer;
begin
StructureView := BorlandIDEServices as IOTAStructureView;
StructureContext := StructureView.GetStructureContext;
for I := 0 to StructureContext.RootNodeCount - 1 do
begin
Node := StructureContext.GetRootStructureNode(I);
TreeToSL(Node, ASL, '');
end;
end;