2008-02-20 06:52:00 +00:00
|
|
|
unit MainFrm;
|
|
|
|
|
2008-04-21 13:04:19 +00:00
|
|
|
{$WARN UNIT_PLATFORM OFF}
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
2008-04-21 13:04:19 +00:00
|
|
|
ComCtrls,
|
2008-02-20 06:52:00 +00:00
|
|
|
Controls,
|
2008-04-21 13:04:19 +00:00
|
|
|
Dialogs,
|
2008-02-20 06:52:00 +00:00
|
|
|
Forms,
|
|
|
|
Mask,
|
|
|
|
StdCtrls,
|
|
|
|
|
2008-04-21 13:04:19 +00:00
|
|
|
cxButtonEdit,
|
|
|
|
cxContainer,
|
|
|
|
cxControls,
|
|
|
|
cxEdit,
|
|
|
|
cxLookAndFeels,
|
|
|
|
cxMaskEdit,
|
|
|
|
cxTextEdit;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
TMainForm = class(TForm)
|
|
|
|
btnClose: TButton;
|
|
|
|
btnGenerate: TButton;
|
2008-04-21 13:04:19 +00:00
|
|
|
DefaultEditStyle: TcxDefaultEditStyleController;
|
|
|
|
deFolder: TcxButtonEdit;
|
|
|
|
dlgOutputFile: TSaveDialog;
|
|
|
|
dlgSchema: TOpenDialog;
|
|
|
|
edtFolderPostfix: TcxTextEdit;
|
|
|
|
edtFolderPrefix: TcxTextEdit;
|
|
|
|
feFile: TcxButtonEdit;
|
|
|
|
feSchema: TcxButtonEdit;
|
2008-02-20 06:52:00 +00:00
|
|
|
gbOutput: TGroupBox;
|
|
|
|
lblFile: TLabel;
|
|
|
|
lblFolder: TLabel;
|
|
|
|
lblFolderPostfix: TLabel;
|
|
|
|
lblFolderPrefix: TLabel;
|
|
|
|
lblSchema: TLabel;
|
2008-04-21 13:04:19 +00:00
|
|
|
LookAndFeel: TcxLookAndFeelController;
|
|
|
|
plOutput: TPageControl;
|
2008-02-20 06:52:00 +00:00
|
|
|
rbFile: TRadioButton;
|
|
|
|
rbFolder: TRadioButton;
|
2008-04-21 13:04:19 +00:00
|
|
|
spFile: TTabSheet;
|
|
|
|
spFolder: TTabSheet;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
procedure btnCloseClick(Sender: TObject);
|
|
|
|
procedure btnGenerateClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
2008-04-14 19:20:55 +00:00
|
|
|
procedure OutputTypeClick(Sender: TObject);
|
2008-04-21 13:04:19 +00:00
|
|
|
procedure feFilePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
|
|
|
procedure deFolderPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
|
|
|
procedure feSchemaPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
2008-04-14 19:20:55 +00:00
|
|
|
private
|
|
|
|
procedure GetFileName(Sender: TObject; const SchemaName: String; var Path, FileName: String);
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
2008-04-21 13:04:19 +00:00
|
|
|
FileCtrl,
|
2008-02-20 06:52:00 +00:00
|
|
|
SysUtils,
|
|
|
|
Windows,
|
|
|
|
|
2008-04-14 19:20:55 +00:00
|
|
|
X2UtTempFile,
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
DelphiXMLDataBindingGenerator,
|
|
|
|
XMLDataBindingGenerator;
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
{ TMainForm }
|
|
|
|
procedure TMainForm.FormCreate(Sender: TObject);
|
2008-04-14 19:20:55 +00:00
|
|
|
var
|
|
|
|
schemaFile: String;
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
|
|
|
plOutput.ActivePageIndex := 0;
|
2008-04-14 19:20:55 +00:00
|
|
|
|
|
|
|
if ParamCount() > 0 then
|
|
|
|
begin
|
|
|
|
schemaFile := ParamStr(1);
|
|
|
|
|
|
|
|
if FileExists(schemaFile) then
|
|
|
|
begin
|
|
|
|
feSchema.Text := schemaFile;
|
|
|
|
feFile.Text := ChangeFileExt(schemaFile, '.pas');
|
|
|
|
deFolder.Text := ExtractFilePath(schemaFile);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TMainForm.OutputTypeClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if Sender = rbFile then
|
|
|
|
plOutput.ActivePage := spFile
|
|
|
|
else if Sender = rbFolder then
|
|
|
|
plOutput.ActivePage := spFolder;
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TMainForm.btnGenerateClick(Sender: TObject);
|
|
|
|
begin
|
2008-04-21 13:04:19 +00:00
|
|
|
if not FileExists(feSchema.Text) then
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
|
|
|
MessageBox(Self.Handle, 'Please specify a valid schema file.',
|
|
|
|
'Schema file does not exist', MB_OK or MB_ICONERROR);
|
|
|
|
|
|
|
|
ActiveControl := feFile;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
with TDelphiXMLDataBindingGenerator.Create() do
|
|
|
|
try
|
2008-04-14 19:20:55 +00:00
|
|
|
if rbFile.Checked then
|
|
|
|
begin
|
|
|
|
OutputType := otSingle;
|
2008-04-21 13:04:19 +00:00
|
|
|
OutputPath := feFile.Text;
|
2008-04-14 19:20:55 +00:00
|
|
|
end else if rbFolder.Checked then
|
|
|
|
begin
|
|
|
|
OutputType := otMultiple;
|
|
|
|
OutputPath := deFolder.Text;
|
|
|
|
end;
|
|
|
|
|
|
|
|
OnGetFileName := GetFileName;
|
2008-04-21 13:04:19 +00:00
|
|
|
Execute(feSchema.Text);
|
|
|
|
|
|
|
|
ShowMessage('The data binding has been generated.');
|
2008-02-20 06:52:00 +00:00
|
|
|
finally
|
|
|
|
Free();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TMainForm.btnCloseClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Close();
|
|
|
|
end;
|
|
|
|
|
2008-04-14 19:20:55 +00:00
|
|
|
|
|
|
|
procedure TMainForm.GetFileName(Sender: TObject; const SchemaName: String; var Path, FileName: String);
|
|
|
|
begin
|
2008-04-14 19:36:55 +00:00
|
|
|
FileName := ChangeFileExt(edtFolderPrefix.Text + FileName,
|
|
|
|
edtFolderPostfix.Text + ExtractFileExt(FileName));
|
2008-04-14 19:20:55 +00:00
|
|
|
CheckValidFileName(FileName);
|
|
|
|
end;
|
|
|
|
|
2008-04-21 13:04:19 +00:00
|
|
|
|
|
|
|
procedure TMainForm.feFilePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
|
|
|
begin
|
|
|
|
if dlgOutputFile.Execute() then
|
|
|
|
feFile.Text := dlgOutputFile.FileName;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TMainForm.deFolderPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
|
|
|
var
|
|
|
|
directory: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if SelectDirectory('Select output folder', '', directory) then
|
|
|
|
deFolder.Text := directory;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TMainForm.feSchemaPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
|
|
|
begin
|
|
|
|
if dlgSchema.Execute() then
|
|
|
|
feSchema.Text := dlgSchema.FileName;
|
|
|
|
end;
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
end.
|