Initial commit
This commit is contained in:
parent
13e62cc619
commit
95a306f0b1
180
Forms/MainFrm.dfm
Normal file
180
Forms/MainFrm.dfm
Normal file
@ -0,0 +1,180 @@
|
||||
object MainForm: TMainForm
|
||||
Left = 238
|
||||
Top = 81
|
||||
BorderIcons = [biSystemMenu, biMinimize]
|
||||
BorderStyle = bsDialog
|
||||
Caption = 'X'#178'Software XML Data Binding Wizard for Delphi'
|
||||
ClientHeight = 244
|
||||
ClientWidth = 438
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'Tahoma'
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCreate = FormCreate
|
||||
DesignSize = (
|
||||
438
|
||||
244)
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object lblSchema: TLabel
|
||||
Left = 8
|
||||
Top = 11
|
||||
Width = 58
|
||||
Height = 13
|
||||
Caption = 'Schema file:'
|
||||
end
|
||||
object feSchema: TJvFilenameEdit
|
||||
Left = 99
|
||||
Top = 8
|
||||
Width = 331
|
||||
Height = 21
|
||||
AddQuotes = False
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
TabOrder = 0
|
||||
Text = 'F:\XTxXSD\Offerte.xsd'
|
||||
end
|
||||
object gbOutput: TGroupBox
|
||||
Left = 8
|
||||
Top = 43
|
||||
Width = 422
|
||||
Height = 162
|
||||
Anchors = [akLeft, akTop, akBottom]
|
||||
Caption = ' Output '
|
||||
TabOrder = 1
|
||||
DesignSize = (
|
||||
422
|
||||
162)
|
||||
object rbFile: TRadioButton
|
||||
Left = 7
|
||||
Top = 21
|
||||
Width = 126
|
||||
Height = 17
|
||||
Caption = 'Output to &single file'
|
||||
Checked = True
|
||||
TabOrder = 0
|
||||
TabStop = True
|
||||
end
|
||||
object rbFolder: TRadioButton
|
||||
Left = 8
|
||||
Top = 44
|
||||
Width = 149
|
||||
Height = 17
|
||||
Caption = 'Output to separate &files'
|
||||
Enabled = False
|
||||
TabOrder = 1
|
||||
end
|
||||
object plOutput: TJvPageList
|
||||
Left = 3
|
||||
Top = 72
|
||||
Width = 416
|
||||
Height = 87
|
||||
ActivePage = spFile
|
||||
PropagateEnable = False
|
||||
ShowDesignCaption = sdcBottomRight
|
||||
Anchors = [akLeft, akTop, akRight, akBottom]
|
||||
object spFile: TJvStandardPage
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 416
|
||||
Height = 87
|
||||
object lblFile: TLabel
|
||||
Left = 8
|
||||
Top = 7
|
||||
Width = 55
|
||||
Height = 13
|
||||
Caption = 'Output file:'
|
||||
end
|
||||
object feFile: TJvFilenameEdit
|
||||
Left = 88
|
||||
Top = 3
|
||||
Width = 321
|
||||
Height = 21
|
||||
AddQuotes = False
|
||||
TabOrder = 0
|
||||
Text = 'F:\XTxXSD\Output\xml_Offerte.pas'
|
||||
end
|
||||
end
|
||||
object spFolder: TJvStandardPage
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 416
|
||||
Height = 87
|
||||
DesignSize = (
|
||||
416
|
||||
87)
|
||||
object lblFolder: TLabel
|
||||
Left = 8
|
||||
Top = 7
|
||||
Width = 69
|
||||
Height = 13
|
||||
Caption = 'Output folder:'
|
||||
end
|
||||
object lblFolderPrefix: TLabel
|
||||
Left = 8
|
||||
Top = 34
|
||||
Width = 51
|
||||
Height = 13
|
||||
Caption = 'File prefix:'
|
||||
end
|
||||
object lblFolderPostfix: TLabel
|
||||
Left = 8
|
||||
Top = 60
|
||||
Width = 56
|
||||
Height = 13
|
||||
Caption = 'File postfix:'
|
||||
end
|
||||
object deFolder: TJvDirectoryEdit
|
||||
Left = 88
|
||||
Top = 3
|
||||
Width = 321
|
||||
Height = 21
|
||||
DialogKind = dkWin32
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
TabOrder = 0
|
||||
Text = 'F:\XTxXSD\Output\'
|
||||
end
|
||||
object edtFolderPrefix: TEdit
|
||||
Left = 88
|
||||
Top = 30
|
||||
Width = 121
|
||||
Height = 21
|
||||
TabOrder = 1
|
||||
Text = 'xml_'
|
||||
end
|
||||
object edtFolderPostfix: TEdit
|
||||
Left = 88
|
||||
Top = 57
|
||||
Width = 121
|
||||
Height = 21
|
||||
TabOrder = 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
object btnGenerate: TButton
|
||||
Left = 274
|
||||
Top = 211
|
||||
Width = 75
|
||||
Height = 25
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = '&Generate'
|
||||
Default = True
|
||||
TabOrder = 2
|
||||
OnClick = btnGenerateClick
|
||||
end
|
||||
object btnClose: TButton
|
||||
Left = 355
|
||||
Top = 211
|
||||
Width = 75
|
||||
Height = 25
|
||||
Anchors = [akRight, akBottom]
|
||||
Cancel = True
|
||||
Caption = '&Close'
|
||||
TabOrder = 3
|
||||
OnClick = btnCloseClick
|
||||
end
|
||||
end
|
92
Forms/MainFrm.pas
Normal file
92
Forms/MainFrm.pas
Normal file
@ -0,0 +1,92 @@
|
||||
unit MainFrm;
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes,
|
||||
Controls,
|
||||
Forms,
|
||||
Mask,
|
||||
StdCtrls,
|
||||
|
||||
JvComponent,
|
||||
JvExControls,
|
||||
JvExMask,
|
||||
JvPageList,
|
||||
JvToolEdit;
|
||||
|
||||
|
||||
type
|
||||
TMainForm = class(TForm)
|
||||
btnClose: TButton;
|
||||
btnGenerate: TButton;
|
||||
deFolder: TJvDirectoryEdit;
|
||||
edtFolderPostfix: TEdit;
|
||||
edtFolderPrefix: TEdit;
|
||||
feFile: TJvFilenameEdit;
|
||||
feSchema: TJvFilenameEdit;
|
||||
gbOutput: TGroupBox;
|
||||
lblFile: TLabel;
|
||||
lblFolder: TLabel;
|
||||
lblFolderPostfix: TLabel;
|
||||
lblFolderPrefix: TLabel;
|
||||
lblSchema: TLabel;
|
||||
plOutput: TJvPageList;
|
||||
rbFile: TRadioButton;
|
||||
rbFolder: TRadioButton;
|
||||
spFile: TJvStandardPage;
|
||||
spFolder: TJvStandardPage;
|
||||
|
||||
procedure btnCloseClick(Sender: TObject);
|
||||
procedure btnGenerateClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
SysUtils,
|
||||
Windows,
|
||||
|
||||
DelphiXMLDataBindingGenerator,
|
||||
XMLDataBindingGenerator;
|
||||
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
|
||||
{ TMainForm }
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
plOutput.ActivePageIndex := 0;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMainForm.btnGenerateClick(Sender: TObject);
|
||||
begin
|
||||
if not FileExists(feSchema.FileName) then
|
||||
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
|
||||
OutputType := otSingle;
|
||||
OutputPath := feFile.FileName;
|
||||
|
||||
Execute(feSchema.FileName);
|
||||
finally
|
||||
Free();
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMainForm.btnCloseClick(Sender: TObject);
|
||||
begin
|
||||
Close();
|
||||
end;
|
||||
|
||||
end.
|
202
Units/DelphiXMLDataBindingGenerator.pas
Normal file
202
Units/DelphiXMLDataBindingGenerator.pas
Normal file
@ -0,0 +1,202 @@
|
||||
unit DelphiXMLDataBindingGenerator;
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes,
|
||||
XMLSchema,
|
||||
|
||||
XMLDataBindingGenerator,
|
||||
XMLDataBindingHelpers;
|
||||
|
||||
type
|
||||
TGetFileNameEvent = procedure(Sender: TObject; const SchemaName: String; var Result: String) of object;
|
||||
|
||||
TDelphiXMLDataBindingGenerator = class(TXMLDataBindingGenerator)
|
||||
private
|
||||
FOnGetFileName: TGetFileNameEvent;
|
||||
protected
|
||||
procedure GenerateDataBinding(); override;
|
||||
procedure GenerateSingleDataBinding();
|
||||
procedure GenerateMultipleDataBinding();
|
||||
|
||||
function DoGetFileName(const ASchemaName: String): String;
|
||||
|
||||
procedure WriteUnitHeader(AStream: TStreamHelper; const AFileName: String);
|
||||
procedure WriteSchemaInterfaces(AStream: TStreamHelper; ASchemaDef: IXMLSchemaDef; AForward: Boolean);
|
||||
procedure WriteElementInterface(AStream: TStreamHelper; AElement: IXMLElementDef; AForward: Boolean);
|
||||
procedure WriteElements(AStream: TStreamHelper; AType: IXMLTypeDef);
|
||||
procedure WriteImplementation(AStream: TStreamHelper);
|
||||
procedure WriteUnitFooter(AStream: TStreamHelper);
|
||||
public
|
||||
property OnGetFileName: TGetFileNameEvent read FOnGetFileName write FOnGetFileName;
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
|
||||
{ TDelphiXMLDataBindingGenerator }
|
||||
procedure TDelphiXMLDataBindingGenerator.GenerateDataBinding();
|
||||
begin
|
||||
case OutputType of
|
||||
otSingle: GenerateSingleDataBinding();
|
||||
otMultiple: GenerateMultipleDataBinding();
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDelphiXMLDataBindingGenerator.GenerateSingleDataBinding();
|
||||
var
|
||||
unitName: String;
|
||||
unitStream: TStreamHelper;
|
||||
schemaIndex: Integer;
|
||||
|
||||
begin
|
||||
unitName := DoGetFileName(Schema[0].SchemaName);
|
||||
unitStream := TStreamHelper.Create(TFileStream.Create(unitName, fmCreate), soOwned);
|
||||
try
|
||||
WriteUnitHeader(unitStream, unitName);
|
||||
unitStream.WriteLn('type');
|
||||
|
||||
for schemaIndex := 0 to Pred(SchemaCount) do
|
||||
begin
|
||||
unitStream.WriteLn(' { Forward declarations for ' + Schema[schemaIndex].SchemaName + ' }');
|
||||
WriteSchemaInterfaces(unitStream, Schema[schemaIndex].SchemaDef, True);
|
||||
end;
|
||||
|
||||
for schemaIndex := 0 to Pred(SchemaCount) do
|
||||
begin
|
||||
unitStream.WriteLn(' { Interfaces for ' + Schema[schemaIndex].SchemaName + ' }');
|
||||
WriteSchemaInterfaces(unitStream, Schema[schemaIndex].SchemaDef, False);
|
||||
end;
|
||||
|
||||
WriteImplementation(unitStream);
|
||||
WriteUnitFooter(unitStream);
|
||||
finally
|
||||
FreeAndNil(unitStream);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDelphiXMLDataBindingGenerator.GenerateMultipleDataBinding();
|
||||
begin
|
||||
end;
|
||||
|
||||
|
||||
procedure TDelphiXMLDataBindingGenerator.WriteUnitHeader(AStream: TStreamHelper; const AFileName: String);
|
||||
begin
|
||||
// #ToDo1 (MvR) 14-4-2007: if outputtype = multiple, use include files
|
||||
|
||||
AStream.WriteLn('{');
|
||||
AStream.WriteLn(' X2Software XML Data Binding Wizard');
|
||||
AStream.WriteLn(' Generated from: ' + SourceFileName);
|
||||
AStream.WriteLn('}');
|
||||
AStream.WriteLn('unit ' + ChangeFileExt(ExtractFileName(AFileName), '') + ';');
|
||||
AStream.WriteLn();
|
||||
AStream.WriteLn('interface');
|
||||
AStream.WriteLn('uses');
|
||||
AStream.WriteLn(' XMLDoc,');
|
||||
AStream.WriteLn(' XMLIntf;');
|
||||
AStream.WriteLn();
|
||||
end;
|
||||
|
||||
|
||||
procedure TDelphiXMLDataBindingGenerator.WriteSchemaInterfaces(AStream: TStreamHelper; ASchemaDef: IXMLSchemaDef; AForward: Boolean);
|
||||
|
||||
procedure ProcessElementDefs(AElements: IXMLElementDefList);
|
||||
var
|
||||
elementIndex: Integer;
|
||||
element: IXMLElementDef;
|
||||
|
||||
begin
|
||||
for elementIndex := 0 to Pred(AElements.Count) do
|
||||
begin
|
||||
element := AElements[elementIndex];
|
||||
|
||||
if element.DataType.IsComplex then
|
||||
begin
|
||||
WriteElementInterface(AStream, element, AForward);
|
||||
ProcessElementDefs(element.ChildElements);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
elementIndex: Integer;
|
||||
element: IXMLElementDef;
|
||||
complexTypeIndex: Integer;
|
||||
complexType: IXMLComplexTypeDef;
|
||||
|
||||
begin
|
||||
for elementIndex := 0 to Pred(ASchemaDef.ElementDefs.Count) do
|
||||
begin
|
||||
element := ASchemaDef.ElementDefs[elementIndex];
|
||||
|
||||
WriteElementInterface(AStream, element, AForward);
|
||||
if element.DataType.IsComplex then
|
||||
begin
|
||||
ProcessElementDefs(element.ChildElements);
|
||||
end;
|
||||
end;
|
||||
|
||||
for complexTypeIndex := 0 to Pred(ASchemaDef.ComplexTypes.Count) do
|
||||
begin
|
||||
complexType := ASchemaDef.ComplexTypes[complexTypeIndex];
|
||||
|
||||
if AForward then
|
||||
begin
|
||||
AStream.WriteLn(' IXML' + complexType.Name + ' = interface; { ComplexType }');
|
||||
end else
|
||||
begin
|
||||
AStream.WriteLn(' IXML' + complexType.Name + ' = interface');
|
||||
AStream.WriteLn(' {TODO:GUID}');
|
||||
|
||||
WriteElements(complexType);
|
||||
|
||||
AStream.WriteLn(' end;');
|
||||
AStream.WriteLn();
|
||||
end;
|
||||
|
||||
ProcessElementDefs(complexType.ElementDefList);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDelphiXMLDataBindingGenerator.WriteElementInterface(AStream: TStreamHelper; AElement: IXMLElementDef; AForward: Boolean);
|
||||
begin
|
||||
if AForward then
|
||||
begin
|
||||
AStream.WriteLn(' IXML' + AElement.Name + ' = interface; { ElementDef }');
|
||||
end else
|
||||
begin
|
||||
// #ToDo1 (MvR) 14-4-2007: output element interface
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDelphiXMLDataBindingGenerator.WriteImplementation(AStream: TStreamHelper);
|
||||
begin
|
||||
end;
|
||||
|
||||
|
||||
procedure TDelphiXMLDataBindingGenerator.WriteUnitFooter(AStream: TStreamHelper);
|
||||
begin
|
||||
AStream.WriteLn();
|
||||
AStream.WriteLn('end.');
|
||||
end;
|
||||
|
||||
|
||||
function TDelphiXMLDataBindingGenerator.DoGetFileName(const ASchemaName: String): String;
|
||||
begin
|
||||
Result := OutputPath;
|
||||
|
||||
if OutputType = otMultiple then
|
||||
begin
|
||||
Result := IncludeTrailingPathDelimiter(Result) + ASchemaName + '.pas';
|
||||
if Assigned(FOnGetFileName) then
|
||||
FOnGetFileName(Self, ASchemaName, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
198
Units/XMLDataBindingGenerator.pas
Normal file
198
Units/XMLDataBindingGenerator.pas
Normal file
@ -0,0 +1,198 @@
|
||||
unit XMLDataBindingGenerator;
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes,
|
||||
Contnrs,
|
||||
XMLSchema;
|
||||
|
||||
type
|
||||
TXMLDataBindingSchema = class(TObject)
|
||||
private
|
||||
FSchemaDef: IXMLSchemaDef;
|
||||
FSchemaName: String;
|
||||
public
|
||||
property SchemaDef: IXMLSchemaDef read FSchemaDef write FSchemaDef;
|
||||
property SchemaName: String read FSchemaName write FSchemaName;
|
||||
end;
|
||||
|
||||
TXMLDataBindingOutputType = (otSingle, otMultiple);
|
||||
|
||||
TXMLDataBindingGenerator = class(TObject)
|
||||
private
|
||||
FIncludePaths: TStrings;
|
||||
FOutputPath: string;
|
||||
FOutputType: TXMLDataBindingOutputType;
|
||||
FSourceFileName: String;
|
||||
|
||||
FSchemas: TObjectList;
|
||||
|
||||
function GetSchemaCount(): Integer;
|
||||
function GetSchema(Index: Integer): TXMLDataBindingSchema;
|
||||
protected
|
||||
function LoadSchema(const AStream: TStream; const ASchemaName: String): IXMLSchemaDef;
|
||||
function FindSchema(const ALocation: String): TStream;
|
||||
|
||||
procedure GenerateDataBinding(); virtual; abstract;
|
||||
|
||||
property SourceFileName: String read FSourceFileName write FSourceFileName;
|
||||
property SchemaCount: Integer read GetSchemaCount;
|
||||
property Schema[Index: Integer]: TXMLDataBindingSchema read GetSchema;
|
||||
public
|
||||
constructor Create();
|
||||
destructor Destroy(); override;
|
||||
|
||||
procedure Execute(const AStream: TStream; const ASchemaName: String); overload;
|
||||
procedure Execute(const AFileName: String); overload;
|
||||
|
||||
property IncludePaths: TStrings read FIncludePaths;
|
||||
property OutputType: TXMLDataBindingOutputType read FOutputType write FOutputType;
|
||||
property OutputPath: string read FOutputPath write FOutputPath;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
SysUtils,
|
||||
|
||||
XMLDoc,
|
||||
XMLIntf;
|
||||
|
||||
|
||||
{ TXMLDataBindingGenerator }
|
||||
constructor TXMLDataBindingGenerator.Create();
|
||||
begin
|
||||
inherited;
|
||||
|
||||
FIncludePaths := TStringList.Create();
|
||||
FSchemas := TObjectList.Create(True);
|
||||
|
||||
with TStringList(FIncludePaths) do
|
||||
begin
|
||||
CaseSensitive := False;
|
||||
Duplicates := dupIgnore;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
destructor TXMLDataBindingGenerator.Destroy();
|
||||
begin
|
||||
FreeAndNil(FSchemas);
|
||||
FreeAndNil(FIncludePaths);
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
||||
procedure TXMLDataBindingGenerator.Execute(const AStream: TStream; const ASchemaName: String);
|
||||
//var
|
||||
// schemaIndex: Integer;
|
||||
//
|
||||
begin
|
||||
FSchemas.Clear();
|
||||
LoadSchema(AStream, ASchemaName);
|
||||
|
||||
if SchemaCount > 0 then
|
||||
GenerateDataBinding();
|
||||
end;
|
||||
|
||||
|
||||
procedure TXMLDataBindingGenerator.Execute(const AFileName: String);
|
||||
var
|
||||
currentDir: String;
|
||||
fileStream: TFileStream;
|
||||
|
||||
begin
|
||||
currentDir := GetCurrentDir();
|
||||
try
|
||||
ChDir(ExtractFilePath(AFileName));
|
||||
|
||||
fileStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
|
||||
try
|
||||
FSourceFileName := AFileName;
|
||||
IncludePaths.Add(ExtractFilePath(AFileName));
|
||||
|
||||
Execute(fileStream, ChangeFileExt(ExtractFileName(AFileName), ''));
|
||||
finally
|
||||
FreeAndNil(fileStream);
|
||||
end;
|
||||
finally
|
||||
ChDir(currentDir);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
function TXMLDataBindingGenerator.LoadSchema(const AStream: TStream; const ASchemaName: String): IXMLSchemaDef;
|
||||
var
|
||||
includeIndex: Integer;
|
||||
includes: IXMLSchemaIncludes;
|
||||
includeStream: TStream;
|
||||
location: String;
|
||||
schema: TXMLDataBindingSchema;
|
||||
schemaDoc: IXMLSchemaDoc;
|
||||
|
||||
begin
|
||||
schemaDoc := TXMLSchemaDoc.Create(nil);
|
||||
schemaDoc.LoadFromStream(AStream);
|
||||
Result := schemaDoc.SchemaDef;
|
||||
|
||||
schema := TXMLDataBindingSchema.Create();
|
||||
schema.SchemaDef := Result;
|
||||
schema.SchemaName := ASchemaName;
|
||||
FSchemas.Add(schema);
|
||||
|
||||
{ Handle includes }
|
||||
includes := Result.SchemaIncludes;
|
||||
for includeIndex := 0 to Pred(includes.Count) do
|
||||
begin
|
||||
location := includes[includeIndex].SchemaLocation;
|
||||
includeStream := FindSchema(location);
|
||||
|
||||
if Assigned(includeStream) then
|
||||
try
|
||||
location := ChangeFileExt(ExtractFileName(location), '');
|
||||
LoadSchema(includeStream, location);
|
||||
finally
|
||||
FreeAndNil(includeStream);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TXMLDataBindingGenerator.FindSchema(const ALocation: String): TStream;
|
||||
var
|
||||
includeIndex: Integer;
|
||||
includePath: String;
|
||||
|
||||
begin
|
||||
Result := nil;
|
||||
|
||||
// #ToDo3 (MvR) 31-1-2007: support more locations than just a filename ?
|
||||
|
||||
for includeIndex := 0 to Pred(IncludePaths.Count) do
|
||||
begin
|
||||
includePath := IncludeTrailingPathDelimiter(IncludePaths[includeIndex]);
|
||||
|
||||
if FileExists(includePath + ALocation) then
|
||||
begin
|
||||
Result := TFileStream.Create(includePath + ALocation, fmOpenRead or fmShareDenyNone);
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TXMLDataBindingGenerator.GetSchemaCount(): Integer;
|
||||
begin
|
||||
Result := FSchemas.Count;
|
||||
end;
|
||||
|
||||
|
||||
function TXMLDataBindingGenerator.GetSchema(Index: Integer): TXMLDataBindingSchema;
|
||||
begin
|
||||
Result := TXMLDataBindingSchema(FSchemas[Index]);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
128
Units/XMLDataBindingHelpers.pas
Normal file
128
Units/XMLDataBindingHelpers.pas
Normal file
@ -0,0 +1,128 @@
|
||||
unit XMLDataBindingHelpers;
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes;
|
||||
|
||||
type
|
||||
TStreamHelper = class(TObject)
|
||||
private
|
||||
FOwnership: TStreamOwnership;
|
||||
FStream: TStream;
|
||||
public
|
||||
constructor Create(AStream: TStream; AOwnership: TStreamOwnership = soReference);
|
||||
destructor Destroy(); override;
|
||||
|
||||
function ReadString(ASize: Integer = -1): String;
|
||||
function ReadInteger(): Integer;
|
||||
function ReadDateTime(): TDateTime;
|
||||
function ReadBoolean(): Boolean;
|
||||
|
||||
procedure Write(const ASource: String);
|
||||
procedure WriteLn(const ASource: String = '');
|
||||
|
||||
procedure WriteString(const ASource: String);
|
||||
procedure WriteInteger(const ASource: Integer);
|
||||
procedure WriteDateTime(const ASource: TDateTime);
|
||||
procedure WriteBoolean(const ASource: Boolean);
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
|
||||
{ TStreamHelper }
|
||||
constructor TStreamHelper.Create(AStream: TStream; AOwnership: TStreamOwnership);
|
||||
begin
|
||||
FOwnership := AOwnership;
|
||||
FStream := AStream;
|
||||
|
||||
inherited Create();
|
||||
end;
|
||||
|
||||
|
||||
destructor TStreamHelper.Destroy();
|
||||
begin
|
||||
if FOwnership = soOwned then
|
||||
FreeAndNil(FStream);
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
||||
function TStreamHelper.ReadString(ASize: Integer): String;
|
||||
var
|
||||
iSize: Integer;
|
||||
|
||||
begin
|
||||
if ASize = -1 then
|
||||
iSize := ReadInteger()
|
||||
else
|
||||
iSize := ASize;
|
||||
|
||||
SetLength(Result, iSize);
|
||||
FStream.Read(PChar(Result)^, iSize);
|
||||
end;
|
||||
|
||||
|
||||
function TStreamHelper.ReadInteger(): Integer;
|
||||
begin
|
||||
FStream.Read(Result, SizeOf(Integer));
|
||||
end;
|
||||
|
||||
|
||||
function TStreamHelper.ReadDateTime(): TDateTime;
|
||||
begin
|
||||
FStream.Read(Result, SizeOf(TDateTime));
|
||||
end;
|
||||
|
||||
|
||||
function TStreamHelper.ReadBoolean(): Boolean;
|
||||
begin
|
||||
FStream.Read(Result, SizeOf(Boolean));
|
||||
end;
|
||||
|
||||
|
||||
procedure TStreamHelper.Write(const ASource: String);
|
||||
begin
|
||||
FStream.Write(PChar(ASource)^, Length(ASource));
|
||||
end;
|
||||
|
||||
|
||||
procedure TStreamHelper.WriteLn(const ASource: String);
|
||||
begin
|
||||
Write(ASource + #13#10);
|
||||
end;
|
||||
|
||||
|
||||
procedure TStreamHelper.WriteString(const ASource: String);
|
||||
var
|
||||
iSize: Integer;
|
||||
|
||||
begin
|
||||
iSize := Length(ASource);
|
||||
WriteInteger(iSize);
|
||||
FStream.Write(PChar(ASource)^, iSize);
|
||||
end;
|
||||
|
||||
|
||||
procedure TStreamHelper.WriteInteger(const ASource: Integer);
|
||||
begin
|
||||
FStream.Write(ASource, SizeOf(Integer));
|
||||
end;
|
||||
|
||||
|
||||
procedure TStreamHelper.WriteDateTime(const ASource: TDateTime);
|
||||
begin
|
||||
FStream.Write(ASource, SizeOf(TDateTime));
|
||||
end;
|
||||
|
||||
|
||||
procedure TStreamHelper.WriteBoolean(const ASource: Boolean);
|
||||
begin
|
||||
FStream.Write(ASource, SizeOf(Boolean));
|
||||
end;
|
||||
|
||||
end.
|
172
X2XMLDataBinding.bdsproj
Normal file
172
X2XMLDataBinding.bdsproj
Normal file
@ -0,0 +1,172 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<BorlandProject>
|
||||
<PersonalityInfo>
|
||||
<Option>
|
||||
<Option Name="Personality">Delphi.Personality</Option>
|
||||
<Option Name="ProjectType"></Option>
|
||||
<Option Name="Version">1.0</Option>
|
||||
<Option Name="GUID">{983DFCAF-23CA-48A0-A147-D96769428A71}</Option>
|
||||
</Option>
|
||||
</PersonalityInfo>
|
||||
<Delphi.Personality>
|
||||
<Source>
|
||||
<Source Name="MainSource">X2XMLDataBinding.dpr</Source>
|
||||
</Source>
|
||||
<FileVersion>
|
||||
<FileVersion Name="Version">7.0</FileVersion>
|
||||
</FileVersion>
|
||||
<Compiler>
|
||||
<Compiler Name="A">8</Compiler>
|
||||
<Compiler Name="B">0</Compiler>
|
||||
<Compiler Name="C">1</Compiler>
|
||||
<Compiler Name="D">1</Compiler>
|
||||
<Compiler Name="E">0</Compiler>
|
||||
<Compiler Name="F">0</Compiler>
|
||||
<Compiler Name="G">1</Compiler>
|
||||
<Compiler Name="H">1</Compiler>
|
||||
<Compiler Name="I">1</Compiler>
|
||||
<Compiler Name="J">0</Compiler>
|
||||
<Compiler Name="K">0</Compiler>
|
||||
<Compiler Name="L">1</Compiler>
|
||||
<Compiler Name="M">0</Compiler>
|
||||
<Compiler Name="N">1</Compiler>
|
||||
<Compiler Name="O">1</Compiler>
|
||||
<Compiler Name="P">1</Compiler>
|
||||
<Compiler Name="Q">0</Compiler>
|
||||
<Compiler Name="R">0</Compiler>
|
||||
<Compiler Name="S">0</Compiler>
|
||||
<Compiler Name="T">0</Compiler>
|
||||
<Compiler Name="U">0</Compiler>
|
||||
<Compiler Name="V">1</Compiler>
|
||||
<Compiler Name="W">0</Compiler>
|
||||
<Compiler Name="X">1</Compiler>
|
||||
<Compiler Name="Y">1</Compiler>
|
||||
<Compiler Name="Z">1</Compiler>
|
||||
<Compiler Name="ShowHints">True</Compiler>
|
||||
<Compiler Name="ShowWarnings">True</Compiler>
|
||||
<Compiler Name="UnitAliases">WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;</Compiler>
|
||||
<Compiler Name="NamespacePrefix"></Compiler>
|
||||
<Compiler Name="GenerateDocumentation">False</Compiler>
|
||||
<Compiler Name="DefaultNamespace"></Compiler>
|
||||
<Compiler Name="SymbolDeprecated">True</Compiler>
|
||||
<Compiler Name="SymbolLibrary">True</Compiler>
|
||||
<Compiler Name="SymbolPlatform">True</Compiler>
|
||||
<Compiler Name="SymbolExperimental">True</Compiler>
|
||||
<Compiler Name="UnitLibrary">True</Compiler>
|
||||
<Compiler Name="UnitPlatform">True</Compiler>
|
||||
<Compiler Name="UnitDeprecated">True</Compiler>
|
||||
<Compiler Name="UnitExperimental">True</Compiler>
|
||||
<Compiler Name="HResultCompat">True</Compiler>
|
||||
<Compiler Name="HidingMember">True</Compiler>
|
||||
<Compiler Name="HiddenVirtual">True</Compiler>
|
||||
<Compiler Name="Garbage">True</Compiler>
|
||||
<Compiler Name="BoundsError">True</Compiler>
|
||||
<Compiler Name="ZeroNilCompat">True</Compiler>
|
||||
<Compiler Name="StringConstTruncated">True</Compiler>
|
||||
<Compiler Name="ForLoopVarVarPar">True</Compiler>
|
||||
<Compiler Name="TypedConstVarPar">True</Compiler>
|
||||
<Compiler Name="AsgToTypedConst">True</Compiler>
|
||||
<Compiler Name="CaseLabelRange">True</Compiler>
|
||||
<Compiler Name="ForVariable">True</Compiler>
|
||||
<Compiler Name="ConstructingAbstract">True</Compiler>
|
||||
<Compiler Name="ComparisonFalse">True</Compiler>
|
||||
<Compiler Name="ComparisonTrue">True</Compiler>
|
||||
<Compiler Name="ComparingSignedUnsigned">True</Compiler>
|
||||
<Compiler Name="CombiningSignedUnsigned">True</Compiler>
|
||||
<Compiler Name="UnsupportedConstruct">True</Compiler>
|
||||
<Compiler Name="FileOpen">True</Compiler>
|
||||
<Compiler Name="FileOpenUnitSrc">True</Compiler>
|
||||
<Compiler Name="BadGlobalSymbol">True</Compiler>
|
||||
<Compiler Name="DuplicateConstructorDestructor">True</Compiler>
|
||||
<Compiler Name="InvalidDirective">True</Compiler>
|
||||
<Compiler Name="PackageNoLink">True</Compiler>
|
||||
<Compiler Name="PackageThreadVar">True</Compiler>
|
||||
<Compiler Name="ImplicitImport">True</Compiler>
|
||||
<Compiler Name="HPPEMITIgnored">True</Compiler>
|
||||
<Compiler Name="NoRetVal">True</Compiler>
|
||||
<Compiler Name="UseBeforeDef">True</Compiler>
|
||||
<Compiler Name="ForLoopVarUndef">True</Compiler>
|
||||
<Compiler Name="UnitNameMismatch">True</Compiler>
|
||||
<Compiler Name="NoCFGFileFound">True</Compiler>
|
||||
<Compiler Name="ImplicitVariants">True</Compiler>
|
||||
<Compiler Name="UnicodeToLocale">True</Compiler>
|
||||
<Compiler Name="LocaleToUnicode">True</Compiler>
|
||||
<Compiler Name="ImagebaseMultiple">True</Compiler>
|
||||
<Compiler Name="SuspiciousTypecast">True</Compiler>
|
||||
<Compiler Name="PrivatePropAccessor">True</Compiler>
|
||||
<Compiler Name="UnsafeType">False</Compiler>
|
||||
<Compiler Name="UnsafeCode">False</Compiler>
|
||||
<Compiler Name="UnsafeCast">False</Compiler>
|
||||
<Compiler Name="OptionTruncated">True</Compiler>
|
||||
<Compiler Name="WideCharReduced">True</Compiler>
|
||||
<Compiler Name="DuplicatesIgnored">True</Compiler>
|
||||
<Compiler Name="UnitInitSeq">True</Compiler>
|
||||
<Compiler Name="LocalPInvoke">True</Compiler>
|
||||
<Compiler Name="MessageDirective">True</Compiler>
|
||||
<Compiler Name="CodePage"></Compiler>
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Linker Name="MapFile">3</Linker>
|
||||
<Linker Name="OutputObjs">0</Linker>
|
||||
<Linker Name="GenerateHpps">False</Linker>
|
||||
<Linker Name="ConsoleApp">1</Linker>
|
||||
<Linker Name="DebugInfo">False</Linker>
|
||||
<Linker Name="RemoteSymbols">False</Linker>
|
||||
<Linker Name="GenerateDRC">False</Linker>
|
||||
<Linker Name="MinStackSize">16384</Linker>
|
||||
<Linker Name="MaxStackSize">1048576</Linker>
|
||||
<Linker Name="ImageBase">4194304</Linker>
|
||||
<Linker Name="ExeDescription"></Linker>
|
||||
</Linker>
|
||||
<Directories>
|
||||
<Directories Name="OutputDir"></Directories>
|
||||
<Directories Name="UnitOutputDir"></Directories>
|
||||
<Directories Name="PackageDLLOutputDir"></Directories>
|
||||
<Directories Name="PackageDCPOutputDir"></Directories>
|
||||
<Directories Name="SearchPath">$(BDS)\lib\Debug;$(BDS)\Lib\Debug\Indy10</Directories>
|
||||
<Directories Name="Packages"></Directories>
|
||||
<Directories Name="Conditionals">madExcept</Directories>
|
||||
<Directories Name="DebugSourceDirs"></Directories>
|
||||
<Directories Name="UsePackages">False</Directories>
|
||||
</Directories>
|
||||
<Parameters>
|
||||
<Parameters Name="RunParams"></Parameters>
|
||||
<Parameters Name="HostApplication"></Parameters>
|
||||
<Parameters Name="Launcher"></Parameters>
|
||||
<Parameters Name="UseLauncher">False</Parameters>
|
||||
<Parameters Name="DebugCWD"></Parameters>
|
||||
<Parameters Name="Debug Symbols Search Path"></Parameters>
|
||||
<Parameters Name="LoadAllSymbols">True</Parameters>
|
||||
<Parameters Name="LoadUnspecifiedSymbols">False</Parameters>
|
||||
</Parameters>
|
||||
<VersionInfo>
|
||||
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
|
||||
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
|
||||
<VersionInfo Name="MajorVer">1</VersionInfo>
|
||||
<VersionInfo Name="MinorVer">0</VersionInfo>
|
||||
<VersionInfo Name="Release">0</VersionInfo>
|
||||
<VersionInfo Name="Build">0</VersionInfo>
|
||||
<VersionInfo Name="Debug">False</VersionInfo>
|
||||
<VersionInfo Name="PreRelease">False</VersionInfo>
|
||||
<VersionInfo Name="Special">False</VersionInfo>
|
||||
<VersionInfo Name="Private">False</VersionInfo>
|
||||
<VersionInfo Name="DLL">False</VersionInfo>
|
||||
<VersionInfo Name="Locale">1043</VersionInfo>
|
||||
<VersionInfo Name="CodePage">1252</VersionInfo>
|
||||
</VersionInfo>
|
||||
<VersionInfoKeys>
|
||||
<VersionInfoKeys Name="CompanyName"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="FileDescription"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="InternalName"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductName"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="Comments"></VersionInfoKeys>
|
||||
</VersionInfoKeys>
|
||||
</Delphi.Personality>
|
||||
<StarTeamAssociation></StarTeamAssociation>
|
||||
<StarTeamNonRelativeFiles></StarTeamNonRelativeFiles>
|
||||
</BorlandProject>
|
31
X2XMLDataBinding.dpr
Normal file
31
X2XMLDataBinding.dpr
Normal file
@ -0,0 +1,31 @@
|
||||
program X2XMLDataBinding;
|
||||
|
||||
{$WARN SYMBOL_PLATFORM OFF}
|
||||
|
||||
uses
|
||||
madExcept,
|
||||
madLinkDisAsm,
|
||||
madListHardware,
|
||||
madListProcesses,
|
||||
madListModules,
|
||||
Forms,
|
||||
MainFrm in 'Forms\MainFrm.pas' {MainForm},
|
||||
XMLDataBindingGenerator in 'Units\XMLDataBindingGenerator.pas',
|
||||
DelphiXMLDataBindingGenerator in 'Units\DelphiXMLDataBindingGenerator.pas',
|
||||
XMLDataBindingHelpers in 'Units\XMLDataBindingHelpers.pas';
|
||||
|
||||
{$R *.res}
|
||||
|
||||
var
|
||||
MainForm: TMainForm;
|
||||
|
||||
begin
|
||||
{$IFDEF VER180}
|
||||
ReportMemoryLeaksOnShutdown := (DebugHook <> 0);
|
||||
{$ENDIF}
|
||||
|
||||
Application.Initialize;
|
||||
Application.Title := 'X²Software XML Data Binding Wizard for Delphi';
|
||||
Application.CreateForm(TMainForm, MainForm);
|
||||
Application.Run;
|
||||
end.
|
BIN
X2XMLDataBinding.res
Normal file
BIN
X2XMLDataBinding.res
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user