• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Export Project Source Code

I have written a delphi program and I want to have all the source for all the forms in single text document.  I know I can use something like editpro to open each form and save it as a text but that would take hours.  Is there some program that can take the code from all the forms at once and export it to a text file?
0
mcmahling
Asked:
mcmahling
  • 4
  • 2
  • 2
1 Solution
 
TheRealLokiSenior DeveloperCommented:
from delphi 5 onwards, the form text is saved in a text readable format by default. (.dfm)

If you would like to see the form text in design mode, simply click on the form, right click and choose "view form as text"
you can then right click and view it as normal.
0
 
mokuleCommented:
I think mcmahling mean something different
i would advice
copy *.pas dest.txt
0
 
shaneholmesCommented:
Do you want the text from the *.dfm files as well as the text from the *.pas files, or just the *.pas files text?

sholmes
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
mokuleCommented:
If You want convert dfm files from binery to text before merging use delphi program convert.exe
0
 
TheRealLokiSenior DeveloperCommented:
ALT-Tools-Environment Options

"New Forms as Text"      Toggles the format in which form files are saved. The form files in your project can be saved in one of two formats: binary or text. Text files can be modified more easily by other tools and managed by a version control system. Binary files are backward compatible with earlier versions of Delphi. (You can override this setting on individual forms by right-clicking and checking or unchecking the Text DFM command.)

now, in dos,
cd c:\mysourcedirectory
copy *.dfm All_DFM.txt
copy *.pas All_PAS.txt
0
 
shaneholmesCommented:
Here is an example delphi project which you can run it in the project folder and it will load all *.pas, & *.dfm files into one document and allow you to save it to a file (text)

Hope this helps!

sholmes  -


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl;

type
  TForm1 = class(TForm)
    btnLoad: TButton;
    memMain: TMemo;
    btnSave: TButton;
    lbxFiles: TFileListBox;
    dlgSave: TSaveDialog;
    procedure btnLoadClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnLoadClick(Sender: TObject);
var
 I, J: Integer;
 SL: TStringList;
begin
 SL:= TStringList.Create;
 for I:= 0 to lbxFiles.Count - 1 do
 begin
  SL.LoadFromFile(lbxFiles.Items[I]);
  memMain.Lines.Add(ExtractFileName(lbxFiles.Items[I]));
  memMain.Lines.Add('');
  memMain.Lines.Add('------------------------------');
  memMain.Lines.Add('');
  for J:= 0 to SL.Count - 1 do
   memMain.Lines.Add(SL[J]);
  SL.Clear;
 end;
 SL.Free;
end;

procedure TForm1.btnSaveClick(Sender: TObject);
begin
 if dlgSave.Execute then
  memMain.Lines.SaveToFile(dlgSave.FileName);
end;

end.




object Form1: TForm1
  Left = 201
  Top = 145
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnLoad: TButton
    Left = 40
    Top = 104
    Width = 75
    Height = 25
    Caption = 'Load'
    TabOrder = 0
    OnClick = btnLoadClick
  end
  object memMain: TMemo
    Left = 144
    Top = 96
    Width = 689
    Height = 473
    TabOrder = 1
  end
  object btnSave: TButton
    Left = 40
    Top = 136
    Width = 75
    Height = 25
    Caption = 'Save'
    TabOrder = 2
    OnClick = btnSaveClick
  end
  object lbxFiles: TFileListBox
    Left = 48
    Top = 224
    Width = 57
    Height = 97
    ItemHeight = 13
    Mask = '*.pas;*.dfm'
    TabOrder = 3
    Visible = False
  end
  object dlgSave: TSaveDialog
    DefaultExt = 'txt'
    Filter = 'Text File (*.txt)|*.txt'
    Left = 72
    Top = 192
  end
end
0
 
shaneholmesCommented:
You will need the following components to build the application

2 TButtons
1 TMemo
1 TFileListBox
1 TSaveDialog

Set their properties to the property values shown in the DFM text i posted.

sholmes
0
 
shaneholmesCommented:
This change in the routine adds a line at the end of every file

procedure TForm1.btnLoadClick(Sender: TObject);
var
 I, J: Integer;
 SL: TStringList;
begin
 SL:= TStringList.Create;
 for I:= 0 to lbxFiles.Count - 1 do
 begin
  SL.LoadFromFile(lbxFiles.Items[I]);
  memMain.Lines.Add(ExtractFileName(lbxFiles.Items[I]));
  memMain.Lines.Add('');
  memMain.Lines.Add('------------------------------');
  memMain.Lines.Add('');
  for J:= 0 to SL.Count - 1 do
   memMain.Lines.Add(SL[J]);
  memMain.Lines.Add('');
  memMain.Lines.Add('------------------------------');
  memMain.Lines.Add('');
  SL.Clear;
 end;
 SL.Free;
end;

NOTE: if you do not want the *.dfm files, you can remove them from the mask of the TFileListbox

so you would have just - *.pas  - vs-    *.pas;*.dfm

sholmes


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now