Сохраняя Delphi DFM файлы в синхронизации с их PAS файлами

Обновить

April 2019

Просмотры

148 раз

-2

У меня есть проект Delphi с большим количеством DFM файлов и соответствующих PAS - файлов. Я могу компилировать PAS путем восстановления только проект, но как восстановить и сохранить файлы DFM в синхронизации с их PAS файлами?
Сейчас я получаю много «[Variable.field] не имеет соответствующего компонента. Удалите заявление?» запрашивает из IDE.

2 ответы

3

The simple answer is: Use the Delphi IDE for editing your form related .PAS files whose job it is to keep them in sync.

12

The solution is simple.

  1. Do not edit a .pas file outside the IDE if it has an associated .dfm.

  2. Do not edit the .dfm outside the IDE.

  3. Do not edit the section of the .pas file that is owned by the IDE, which is the part between the opening of the form class definition and the first private section.

    type
      TForm1 = class(TForm)
        // Form designer property - keep out
        // It is where the IDE adds components you drag/drop, event handlers 
        // generated via the Object Inspector or automatically by the IDE.
        // It is the published section, and is used by the VCL streaming
        // system to create controls that are on the form and attach event
        // handlers at runtime. Leave it alone. If you need something in
        // a published state, add a new published section below the private
        // section.
      private
        // Yours - edit all you want
      public
        // Yours - edit all you want
      end;
    
  4. If you need to delete a component from the form, do so by first removing code from any event handlers (you can find them using the Object Inspector), leaving just the empty method shell (consisting of the procedure name, followed by a begin, blank line, and end), and then select the component on the form and hit delete. The IDE will remove the declaration from both the first section of the .pas file and the .dfm and remove the empty event handlers.