2018-09-27 12:26:50 +02:00
|
|
|
unit MainFormU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows,
|
|
|
|
Winapi.Messages,
|
|
|
|
System.SysUtils,
|
|
|
|
System.Variants,
|
|
|
|
System.Classes,
|
|
|
|
Vcl.Graphics,
|
|
|
|
Vcl.Controls,
|
|
|
|
Vcl.Forms,
|
|
|
|
Vcl.Dialogs,
|
|
|
|
FireDAC.Stan.Intf,
|
|
|
|
FireDAC.Stan.Option,
|
|
|
|
FireDAC.Stan.Error,
|
|
|
|
FireDAC.UI.Intf,
|
|
|
|
FireDAC.Phys.Intf,
|
|
|
|
FireDAC.Stan.Def,
|
|
|
|
FireDAC.Stan.Pool,
|
|
|
|
FireDAC.Stan.Async,
|
|
|
|
FireDAC.Phys,
|
|
|
|
FireDAC.Stan.Param,
|
|
|
|
FireDAC.DatS,
|
|
|
|
FireDAC.DApt.Intf,
|
|
|
|
FireDAC.DApt,
|
|
|
|
FireDAC.VCLUI.Wait,
|
|
|
|
FireDAC.Comp.UI,
|
|
|
|
FireDAC.Phys.IBBase,
|
|
|
|
FireDAC.Phys.FB,
|
|
|
|
Data.DB,
|
|
|
|
FireDAC.Comp.DataSet,
|
|
|
|
FireDAC.Comp.Client,
|
|
|
|
Vcl.StdCtrls,
|
|
|
|
Vcl.ExtCtrls,
|
|
|
|
FireDAC.Phys.ODBCBase,
|
|
|
|
FireDAC.Phys.MSSQL,
|
|
|
|
FireDAC.Phys.MSSQLDef,
|
|
|
|
FireDAC.Phys.FBDef,
|
|
|
|
Vcl.ComCtrls,
|
|
|
|
Vcl.Grids,
|
2018-10-23 16:18:34 +02:00
|
|
|
Vcl.ValEdit,
|
|
|
|
FireDAC.Phys.MySQLDef,
|
2019-02-21 18:11:14 +01:00
|
|
|
FireDAC.Phys.MySQL, FireDAC.Phys.PGDef, FireDAC.Phys.PG, FireDAC.Phys.IBDef,
|
|
|
|
FireDAC.Phys.IB, FireDAC.Stan.ExprFuncs, FireDAC.Phys.SQLiteDef,
|
|
|
|
FireDAC.Phys.SQLite;
|
2018-09-27 12:26:50 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
TMainForm = class(TForm)
|
|
|
|
FDConnection1: TFDConnection;
|
|
|
|
Panel1: TPanel;
|
|
|
|
Panel2: TPanel;
|
|
|
|
qry: TFDQuery;
|
|
|
|
FDPhysFBDriverLink1: TFDPhysFBDriverLink;
|
|
|
|
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
|
|
|
|
Splitter1: TSplitter;
|
|
|
|
mmConnectionParams: TMemo;
|
|
|
|
Label2: TLabel;
|
|
|
|
FDPhysMSSQLDriverLink1: TFDPhysMSSQLDriverLink;
|
|
|
|
cboConnectionDefs: TComboBox;
|
|
|
|
Panel3: TPanel;
|
|
|
|
Panel4: TPanel;
|
|
|
|
btnGenEntities: TButton;
|
|
|
|
PageControl1: TPageControl;
|
|
|
|
TabSheet1: TTabSheet;
|
|
|
|
TabSheet2: TTabSheet;
|
|
|
|
btnGetTables: TButton;
|
|
|
|
veTablesMapping: TValueListEditor;
|
|
|
|
mmOutput: TMemo;
|
|
|
|
Panel5: TPanel;
|
|
|
|
btnSaveCode: TButton;
|
|
|
|
FileSaveDialog1: TFileSaveDialog;
|
2018-10-23 16:18:34 +02:00
|
|
|
FDPhysMySQLDriverLink1: TFDPhysMySQLDriverLink;
|
2019-02-21 18:11:14 +01:00
|
|
|
FDPhysPgDriverLink1: TFDPhysPgDriverLink;
|
|
|
|
FDPhysFBDriverLink2: TFDPhysFBDriverLink;
|
|
|
|
FDPhysIBDriverLink1: TFDPhysIBDriverLink;
|
|
|
|
FDPhysMySQLDriverLink2: TFDPhysMySQLDriverLink;
|
|
|
|
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
|
2018-09-27 12:26:50 +02:00
|
|
|
procedure btnGenEntitiesClick(Sender: TObject);
|
|
|
|
procedure btnGetTablesClick(Sender: TObject);
|
|
|
|
procedure btnSaveCodeClick(Sender: TObject);
|
|
|
|
procedure cboConnectionDefsChange(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
|
|
private
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff, fImplBuff: TStringStream;
|
2018-09-27 12:26:50 +02:00
|
|
|
FHistoryFileName: string;
|
2018-10-23 16:18:34 +02:00
|
|
|
lTypesName: TArray<string>;
|
|
|
|
procedure EmitHeaderComments;
|
2018-09-27 12:26:50 +02:00
|
|
|
function GetClassName(const aTableName: string): string;
|
|
|
|
procedure EmitUnit;
|
|
|
|
procedure EmitUnitEnd;
|
|
|
|
procedure EmitProperty(F: TField);
|
|
|
|
procedure EmitField(F: TField);
|
|
|
|
procedure EmitClass(const aTableName, aClassName: string);
|
|
|
|
procedure EmitClassEnd;
|
|
|
|
function GetDelphiType(FT: TFieldType): string;
|
2018-10-23 16:18:34 +02:00
|
|
|
function GetFieldName(const Value: string): string;
|
2018-09-27 12:26:50 +02:00
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
MainForm: TMainForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
{Spring.SystemUtils,} System.IOUtils;
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
2018-10-23 16:18:34 +02:00
|
|
|
|
2018-09-27 12:26:50 +02:00
|
|
|
procedure TMainForm.btnGenEntitiesClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
lTableName: string;
|
|
|
|
lClassName: string;
|
|
|
|
F: Integer;
|
2018-10-23 16:18:34 +02:00
|
|
|
lFieldsName: TArray<string>;
|
2018-09-27 12:26:50 +02:00
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.Clear;
|
|
|
|
EmitHeaderComments;
|
2018-09-27 12:26:50 +02:00
|
|
|
EmitUnit;
|
|
|
|
for I := 1 to veTablesMapping.RowCount - 1 do
|
|
|
|
begin
|
|
|
|
lTableName := veTablesMapping.Cells[0, I];
|
|
|
|
lClassName := veTablesMapping.Cells[1, I];
|
|
|
|
EmitClass(lTableName, lClassName);
|
|
|
|
qry.Open('select * from ' + lTableName + ' where 1=0');
|
|
|
|
|
2018-10-23 16:18:34 +02:00
|
|
|
lFieldsName := [];
|
|
|
|
lTypesName := [];
|
|
|
|
fIntfBuff.WriteString('private' + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
for F := 0 to qry.Fields.Count - 1 do
|
|
|
|
begin
|
|
|
|
EmitField(qry.Fields[F]);
|
2018-10-23 16:18:34 +02:00
|
|
|
|
|
|
|
if GetDelphiType(qry.Fields[F].DataType) = 'TStream' then
|
|
|
|
begin
|
|
|
|
lFieldsName := lFieldsName + [GetFieldName(qry.Fields[F].FieldName)];
|
|
|
|
lTypesName := lTypesName + ['TMemoryStream'];
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
fIntfBuff.WriteString('public' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString(' constructor Create; override;' + sLineBreak);
|
|
|
|
|
|
|
|
fImplBuff.WriteString('constructor ' + lClassName + '.Create;' + sLineBreak);
|
|
|
|
fImplBuff.WriteString('begin' + sLineBreak);
|
|
|
|
fImplBuff.WriteString(' inherited Create;' + sLineBreak);
|
|
|
|
for F := low(lFieldsName) to high(lFieldsName) do
|
|
|
|
begin
|
|
|
|
fImplBuff.WriteString(' ' + lFieldsName[F] + ' := ' + lTypesName[F] + '.Create;' + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
2018-10-23 16:18:34 +02:00
|
|
|
fImplBuff.WriteString('end;' + sLineBreak + sLineBreak);
|
|
|
|
|
|
|
|
fIntfBuff.WriteString(' destructor Destroy; override;' + sLineBreak);
|
|
|
|
fImplBuff.WriteString('destructor ' + lClassName + '.Destroy;' + sLineBreak);
|
|
|
|
fImplBuff.WriteString('begin' + sLineBreak);
|
|
|
|
for F := low(lFieldsName) to high(lFieldsName) do
|
|
|
|
begin
|
|
|
|
fImplBuff.WriteString(' ' + lFieldsName[F] + '.Free;' + sLineBreak);
|
|
|
|
end;
|
|
|
|
fImplBuff.WriteString(' inherited;' + sLineBreak);
|
|
|
|
fImplBuff.WriteString('end;' + sLineBreak + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
|
|
|
|
for F := 0 to qry.Fields.Count - 1 do
|
|
|
|
begin
|
|
|
|
EmitProperty(qry.Fields[F]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
EmitClassEnd;
|
|
|
|
end;
|
|
|
|
EmitUnitEnd;
|
2018-10-23 16:18:34 +02:00
|
|
|
mmOutput.Lines.Text := fIntfBuff.DataString + fImplBuff.DataString;
|
2018-09-27 12:26:50 +02:00
|
|
|
|
|
|
|
// mmOutput.Lines.SaveToFile(
|
|
|
|
// mmConnectionParams.Lines.SaveToFile(FHistoryFileName);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.btnGetTablesClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
lTables: TStringList;
|
|
|
|
lTable: string;
|
|
|
|
lClassName: string;
|
|
|
|
begin
|
|
|
|
FDConnection1.Close;
|
|
|
|
FDConnection1.Params.Assign(mmConnectionParams.Lines);
|
|
|
|
FDConnection1.Connected := True;
|
|
|
|
|
|
|
|
lTables := TStringList.Create;
|
|
|
|
try
|
2019-02-21 18:11:14 +01:00
|
|
|
FDConnection1.GetTableNames('', 'public', '', lTables);
|
2018-09-27 12:26:50 +02:00
|
|
|
veTablesMapping.Row := 1;
|
|
|
|
for lTable in lTables do
|
|
|
|
begin
|
|
|
|
lClassName := GetClassName(lTable);
|
|
|
|
veTablesMapping.InsertRow(lTable, lClassName, True);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
lTables.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.btnSaveCodeClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FileSaveDialog1.FileName := 'EntitiesU.pas';
|
|
|
|
if FileSaveDialog1.Execute then
|
|
|
|
begin
|
|
|
|
mmOutput.Lines.SaveToFile(FileSaveDialog1.FileName);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.cboConnectionDefsChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FDManager.GetConnectionDefParams(cboConnectionDefs.Text, mmConnectionParams.Lines);
|
2018-10-23 16:18:34 +02:00
|
|
|
// cbSchema.Items.Clear;
|
|
|
|
// FDConnection1.GetSchemaNames('', '', cbSchema.Items);
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.EmitClass(const aTableName, aClassName: string);
|
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.WriteString('[MVCNameCase(ncLowerCase)]' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString(Format('[MVCTable(''%s'')]', [aTableName]) + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
if trim(aClassName) = '' then
|
|
|
|
raise Exception.Create('Invalid class name');
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.WriteString(aClassName + ' = class(TMVCActiveRecord)' + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.EmitClassEnd;
|
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.WriteString('end;' + sLineBreak + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.EmitField(F: TField);
|
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.WriteString(Format(' [MVCTableField(''%s'')]', [F.FieldName]) + sLineBreak + ' ' + GetFieldName(F.FieldName) + ': ' +
|
2018-09-27 12:26:50 +02:00
|
|
|
GetDelphiType(F.DataType) + ';' + sLineBreak);
|
|
|
|
end;
|
|
|
|
|
2018-10-23 16:18:34 +02:00
|
|
|
procedure TMainForm.EmitHeaderComments;
|
|
|
|
begin
|
|
|
|
fIntfBuff.WriteString('// *************************************************************************** }' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// Delphi MVC Framework' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
2019-01-08 12:48:27 +01:00
|
|
|
fIntfBuff.WriteString('// Copyright (c) 2010-2019 Daniele Teti and the DMVCFramework Team' + sLineBreak);
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// https://github.com/danieleteti/delphimvcframework' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// ***************************************************************************' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// Licensed under the Apache License, Version 2.0 (the "License");' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// you may not use this file except in compliance with the License.' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// You may obtain a copy of the License at' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// http://www.apache.org/licenses/LICENSE-2.0' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// Unless required by applicable law or agreed to in writing, software' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// distributed under the License is distributed on an "AS IS" BASIS,' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// See the License for the specific language governing permissions and' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// limitations under the License.' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('//' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('// ***************************************************************************' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString(sLineBreak);
|
|
|
|
end;
|
|
|
|
|
2018-09-27 12:26:50 +02:00
|
|
|
procedure TMainForm.EmitProperty(F: TField);
|
|
|
|
begin
|
|
|
|
// Buff.WriteString(Format(' [TableField(''%s'')]', [F.FieldName]) + sLineBreak + ' property ' + GetProperCase(F.FieldName) + ': ' +
|
|
|
|
// GetDelphiType(F.DataType) + ';' + sLineBreak);
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.WriteString(' property ' + GetFieldName(F.FieldName).Substring(1) { remove f } + ': ' + GetDelphiType(F.DataType));
|
|
|
|
fIntfBuff.WriteString(' read ' + GetFieldName(F.FieldName) + ' write ' + GetFieldName(F.FieldName));
|
|
|
|
fIntfBuff.WriteString(';' + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.EmitUnit;
|
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.WriteString('unit Entities;' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('interface' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('uses' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString(' MVCFramework.Serializer.Commons,' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString(' MVCFramework.ActiveRecord,' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString(' System.Classes;' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('type' + sLineBreak);
|
|
|
|
fIntfBuff.WriteString('' + sLineBreak);
|
|
|
|
|
|
|
|
fImplBuff.WriteString('implementation' + sLineBreak + sLineBreak);
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.EmitUnitEnd;
|
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fImplBuff.WriteString(sLineBreak + 'end.');
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
|
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff.Free;
|
|
|
|
fImplBuff.Free;
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
2018-10-23 16:18:34 +02:00
|
|
|
fIntfBuff := TStringStream.Create;
|
|
|
|
fImplBuff := TStringStream.Create;
|
2018-09-27 12:26:50 +02:00
|
|
|
FHistoryFileName := TPath.GetDocumentsPath + PathDelim + 'eg.history';
|
|
|
|
try
|
|
|
|
if TFile.Exists(FHistoryFileName) then
|
|
|
|
mmConnectionParams.Lines.LoadFromFile(FHistoryFileName)
|
|
|
|
else
|
|
|
|
mmConnectionParams.Lines.Assign(FDConnection1.Params);
|
|
|
|
except
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
FDManager.LoadConnectionDefFile;
|
|
|
|
FDManager.GetConnectionNames(cboConnectionDefs.Items);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TMainForm.GetClassName(const aTableName: string): string;
|
|
|
|
var
|
|
|
|
lTableName: string;
|
|
|
|
lNextLetter: Integer;
|
|
|
|
lNextLetterChar: string;
|
|
|
|
begin
|
|
|
|
lTableName := aTableName.ToLower;
|
|
|
|
Result := 'T' + lTableName.Substring(0, 1).ToUpper + lTableName.Substring(1).ToLower;
|
|
|
|
|
|
|
|
while Result.IndexOf('_') > -1 do
|
|
|
|
begin
|
|
|
|
lNextLetter := Result.IndexOf('_') + 1;
|
|
|
|
lNextLetterChar := UpperCase(Result.Chars[lNextLetter]);
|
|
|
|
Result := Result.Remove(Result.IndexOf('_') + 1, 1);
|
|
|
|
Result := Result.Insert(Result.IndexOf('_') + 1, lNextLetterChar);
|
|
|
|
Result := Result.Remove(Result.IndexOf('_'), 1);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TMainForm.GetDelphiType(FT: TFieldType): string;
|
|
|
|
begin
|
|
|
|
case FT of
|
|
|
|
ftString:
|
|
|
|
Result := 'String';
|
|
|
|
ftSmallint, ftInteger, ftWord, ftLongWord, ftShortint:
|
|
|
|
Result := 'Integer';
|
|
|
|
ftByte:
|
|
|
|
Result := 'Byte';
|
|
|
|
ftLargeint:
|
|
|
|
Result := 'Int64';
|
|
|
|
ftBoolean:
|
|
|
|
Result := 'Boolean';
|
|
|
|
ftFloat, ftSingle, ftExtended:
|
|
|
|
Result := 'Double';
|
|
|
|
ftCurrency, ftBCD:
|
|
|
|
Result := 'Currency';
|
|
|
|
ftDate:
|
|
|
|
Result := 'TDate';
|
|
|
|
ftTime:
|
|
|
|
Result := 'TTime';
|
|
|
|
ftDateTime:
|
|
|
|
Result := 'TDateTime';
|
|
|
|
ftTimeStamp:
|
|
|
|
Result := 'TDateTime {timestamp}';
|
|
|
|
ftAutoInc:
|
|
|
|
Result := 'Integer; {autoincrement}';
|
|
|
|
ftBlob, ftMemo, ftGraphic, ftFmtMemo, ftWideMemo, ftStream:
|
|
|
|
Result := 'TStream';
|
|
|
|
ftFixedChar:
|
|
|
|
Result := 'String; {fixedchar}';
|
|
|
|
ftWideString:
|
|
|
|
Result := 'String';
|
2019-03-05 20:55:37 +01:00
|
|
|
ftGuid:
|
|
|
|
Result := 'TGuid';
|
2018-09-27 12:26:50 +02:00
|
|
|
else
|
|
|
|
Result := '<UNSUPPORTED TYPE: ' + IntToStr(Ord(FT)) + '>';
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-10-23 16:18:34 +02:00
|
|
|
function TMainForm.GetFieldName(const Value: string): string;
|
2018-09-27 12:26:50 +02:00
|
|
|
var
|
|
|
|
Pieces: TArray<string>;
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
if Value.Length <= 2 then
|
2018-10-23 16:18:34 +02:00
|
|
|
exit('f' + Value.ToUpper);
|
2018-09-27 12:26:50 +02:00
|
|
|
|
|
|
|
Result := '';
|
2019-03-05 20:55:37 +01:00
|
|
|
Pieces := Value.ToLower.Split(['_'], TStringSplitOptions.ExcludeEmpty);
|
2018-09-27 12:26:50 +02:00
|
|
|
for s in Pieces do
|
|
|
|
begin
|
|
|
|
if s = 'id' then
|
|
|
|
Result := Result + 'ID'
|
|
|
|
else
|
|
|
|
Result := Result + UpperCase(s.Chars[0]) + s.Substring(1);
|
|
|
|
end;
|
2018-10-23 16:18:34 +02:00
|
|
|
Result := 'f' + Result;
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|