Code Monkey home page Code Monkey logo

dsdfmparser's People

Contributors

delphi-sucks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dsdfmparser's Issues

proc setproperty and example missed

thank you for your very useful unit!
I only missed an simple example and a proc to set a property value.

procedure TDfmObject.SetProperty(const APropertyName, AValue: String);
begin
  if not HasProperty(APropertyName) then
    TDfmProperty.Create(Self, APropertyName, AValue)
  else
    Properties.GetProperty(APropertyName).Value := AValue;
end;

sample App:

unit uTest;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, DS.DfmParser;

type
  TForm5 = class(TForm)
    Memo1: TMemo;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
    indent: Integer;
    changed: boolean;
    procedure show(text: string);
    procedure ScanFile(filename: string);
    procedure ScanObject(obj: TDfmObject);
  public
    { Public-Deklarationen }
  end;

var
  Form5: TForm5;

implementation

uses System.StrUtils, System.IOUtils;

{$R *.dfm}

procedure TForm5.ScanFile(filename: string);
var
  DfmFile: TDfmFile;
  s: string;
begin
  indent := 0;
  show(filename);

  DfmFile := TDfmFile.Create;
  DfmFile.LoadFromFile(filename);

  indent := 1;
  changed := false;
  for var enum in DfmFile.Objects do
  begin
    ScanObject(enum);
  end;

  if changed then
    DfmFile.Save(filename + '_modified');
end;

procedure TForm5.show(text: string);
begin
  Memo1.Lines.Add(DupeString(#9, indent) + text);
end;

procedure TForm5.Button2Click(Sender: TObject);
var
  filename: String;
begin
  for filename in TDirectory.GetFiles
    ('samples', '*.dfm') do
    ScanFile(filename);
end;

procedure TForm5.ScanObject(obj: TDfmObject);
var
  hint, datafield: string;
begin
  hint := '';
  datafield := '';

  // set hint = datafield
  if obj.HasProperty('datafield') then
  begin
    hint := obj.GetProperty('hint');
    datafield := obj.GetProperty('datafield');
    if datafield <> hint then
    begin
      show(obj.Name);
      show('datafield=' + datafield);
      show('hint=' + hint);

      { Wert ändern }
      obj.SetProperty('hint', datafield);
      changed := true;
    end;
  end;

  { Unterobjekte durchsuchen }
  for var enum in obj.Objects do
  begin
    inc(indent);
    ScanObject(enum);
    dec(indent);
  end;
end;

end.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.