DSDfmParser
1.0.0
Analice y guarde los archivos Delphi DFM modificando los objetos y sus propiedades.
Solo incluya el archivo DS.DfmParser.pas del Src -Directory.
uses DS.DfmParser; var
DfmFile: TDfmFile;
PanelObject: TDfmObject;
PanelCaption: String;
DfmText: String;
begin
DfmFile := TDfmFile.Create;
// Load file
DfmFile.LoadFromFile( ' MyDfmFile.dfm ' );
// Get object (visual element)
DfmObject := DfmFile.GetObject( ' Panel1 ' );
Writeln(DfmObject. Name ); // Panel1
Writeln(DfmObject.ClassName_); // TPanel
// Get properties
PanelCaption := PanelObject.GetProperty( ' Caption ' );
Writeln(PanelCaption); // 'Panel1'
// Set property
PanelObject.SetProperty( ' Caption ' , ' '' MyPanel '' ' )
// Delete property
PanelObject.DeleteProperty( ' Caption ' );
// Save file
DfmFile.Save( ' MyModifiedDfmFile.dfm ' );
// or get the context as string
DfmText := DfmFile.GetDfm;
Writeln(DfmText); // object Form1: TForm1...
DfmFile.Free;
end ; El analizador solo analiza el DFM pero no su contenido. Las cadenas, por ejemplo, están formateadas como cómo se escribiría en Delphi ( 'Caption1' ).
Los valores también pueden ser multiline. Delphi generalmente anula las líneas de valor, pero no debería marcar la diferencia si no lo son. Después de guardar el formulario en Delphi, debe arreglar automáticamente la indención.
Se puede encontrar un proyecto de ejemplo en el example -Directorio.