0

I'm trying to get all occurrencies of the TcxRadioGroup class which have not a value for the Caption property in Delphi DFM files.

I have to do this in a big groupproject with thousands of forms. For this reason I'm looking for a solution which can work on multiple files (I thought to use a RegEx in Notepad++ but I'm open to any other solution)

Example:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 494
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object cxRadioGroup1: TcxRadioGroup
    Left = 0
    Top = 0
    Align = alTop
    Caption = 'cxRadioGroup1'
    Properties.Items = <>
    TabOrder = 0
    ExplicitLeft = 24
    ExplicitTop = 16
    ExplicitWidth = 185
    Height = 105
    Width = 635
  end
  object cxRadioGroup2: TcxRadioGroup
    Left = 0
    Top = 389
    Align = alBottom
    Properties.Items = <>
    TabOrder = 1
    ExplicitTop = 293
    Height = 105
    Width = 635
  end
  object Panel1: TPanel
    Left = 200
    Top = 111
    Width = 257
    Height = 265
    Caption = 'Panel1'
    TabOrder = 2
    object cxRadioGroup3: TcxRadioGroup
      Left = 8
      Top = 16
      Caption = 'cxRadioGroup3'
      Properties.Items = <>
      TabOrder = 0
      Height = 105
      Width = 185
    end
    object cxRadioGroup4: TcxRadioGroup
      Left = 8
      Top = 144
      Properties.Items = <
        item
          Caption = 'item 1'
        end
        item
          Caption = 'item 2'
        end>
      TabOrder = 1
      Height = 105
      Width = 185
    end
  end
end

In this example, I'm expecting to find cxRadioGroup2 and cxRadioGroup4 components.


1° Attempt:

I've tried to use a regular expression but I don't know how to find occurences which have not the Caption line... Using Notepad++, I've started by trying to catch each TcxRadioGroup block until their end line (the end line which has the same indentation).

^\s*object\s(\w*):\sTcxRadioGroup.*end with options /gms

It catches from object cxRadioGroup1 to the last end of the file


2° Attempt:

I've used lazy matching and reused the captured white spaces in order to match the right end for each component declaration.

^(\s*)object\s(\w*):\sTcxRadioGroup.*?\n\1end with options /gms

It finds all TcxRadioGroup declarations, each one from its beginning to its end. I think I should find a way to exclude the ones who contains \1 Caption =

I've prepared an online example.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
  • Could downvoters explain? – Fabrizio Oct 11 '19 at 12:41
  • 1
    This is a typical use case for the Missing Property Report of Pascal Analyzer: https://www.peganza.com/PALHelp/missing_property_report.htm – Uwe Raabe Oct 11 '19 at 12:56
  • RegEx is not a magic bullet... https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Ken Bourassa Oct 11 '19 at 13:26
  • @KenBourassa But in this instance, a regex based script can do the job – David Heffernan Oct 11 '19 at 14:24
  • @Fabrizio This is really a regex question and at least for now I have closed it as such. Really what you are looking for is to use lazy rather than greedy matching. Realistically, Notepad++ isn't really the right tool for working with large numbers of files. You need to write some code to look in all your files. Delphi is also the wrong tool. You should look for a scripting language. I would also reach for Python at this point. – David Heffernan Oct 11 '19 at 14:26
  • @DavidHeffernan: I've edited and re-tagged the question, leaving regex and dfm tags only – Fabrizio Oct 15 '19 at 07:08
  • @DavidHeffernan: Could you please explain why this question is duplicated of [What do 'lazy' and 'greedy' mean in the context of regular expressions?](https://stackoverflow.com/questions/2301285/what-do-lazy-and-greedy-mean-in-the-context-of-regular-expressions). If it was, its solution should solve my question too – Fabrizio Oct 16 '19 at 08:02
  • The question was "It catches from object cxRadioGroup1 to the last end of the file". And that's because of the lazy vs greedy issue. Once you know how to solve that, you can write code to do the rest surely. – David Heffernan Oct 16 '19 at 08:29
  • @DavidHeffernan: The question is (and was) how to find the `TcxRadioGroup` objects which have not the `Caption` property. You're confusing the doubts I had while attempting to solve the question by myself, with the question itself – Fabrizio Oct 16 '19 at 08:39
  • Walk through each line of your dfm files. When you match `object .*: TcxRadioGroup` make a note of the indentation level. Read the following lines and see if you get a `Caption` property with indentation two spaces more. When you reach an `end` with the same indentation as the original `object` then you are done. This won't handle dfm inheritance. But you probably won't have many instances of that so they can be done manually. Use a language like Python to write this code. – David Heffernan Oct 16 '19 at 11:25

0 Answers0