﻿unit InputBox;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, cxLookAndFeelPainters, StdCtrls, cxButtons, ExtCtrls,
  cxMaskEdit, cxDropDownEdit, cxCalendar, cxControls, cxContainer, cxEdit,
  cxTextEdit, cxCurrencyEdit, cxSpinEdit, cxGraphics, cxLookAndFeels, Data.DB,
  OracleData, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, cxTimeEdit,
  cxMemo, cxButtonEdit, cxCheckBox;

type
   TInputDataType = (dtString, dtInteger, dtFloat, dtDate, dtLookup, dtDateTime, dtDBLookup, dtTime, dtMemo, dtButtonEdit, dtSpinEdit, dtCheckBox);

type
   TStringArray = array of string;

type
  Tfrm_InputBox = class(TForm)
    Panel2: TPanel;
    pnValue: TPanel;
    btnOk: TcxButton;
    btnCancel: TcxButton;
    procedure FormShow(Sender: TObject);
  private
    procedure ValueKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure ButtonEditClik(Sender: TObject; AButtonIndex: Integer);
    { Private declarations }
  public
    { Public declarations }
    function InputBox(i_DataType: TInputDataType; i_ValueCaption: String = 'Değeri Giriniz'; i_FormCaption: String = 'Veri Giriş'; i_DefaultValue: String = ''; i_FormWidth: Integer = 500):String;
    function InputQuery(var O_Result: string; i_DataType: TInputDataType; i_ValueCaption: String = 'Değeri Giriniz'; i_FormCaption: String = 'Veri Giriş'; i_DefaultValue: String = ''; i_FormWidth: Integer = 500): Boolean;
    function InputBoxMulti(
         i_DataType: array of TInputDataType;
         i_ValueCaption: array of String;
         i_DefaultValue: array of String;
         i_FormCaption: String;
         i_cancel_button_visible: boolean = True;
         i_FormWidth: Integer = 500;
         i_LabelWidth: Integer = 85): TStringArray;
    function InputBoxMultiQuery(
         var O_Result: TStringArray;
         i_DataType: array of TInputDataType;
         i_ValueCaption: array of String;
         i_DefaultValue: array of String;
         i_FormCaption: String;
         i_cancel_button_visible: boolean = True;
         i_FormWidth: Integer = 500;
         i_LabelWidth: Integer = 85): Boolean;
  end;
var
  frm_InputBox: Tfrm_InputBox;

implementation

uses GFormDataM, Global_Functions, Base_Report;

{$R *.dfm}

function Tfrm_InputBox.InputQuery(var O_Result: string; i_DataType: TInputDataType; i_ValueCaption: String = 'Değeri Giriniz'; i_FormCaption: String = 'Veri Giriş'; i_DefaultValue: String = ''; i_FormWidth: Integer = 500): Boolean;
var
   l_comp: TComponent;
   l_tmp_str, l_Sql,l_Default_Value: String;
   l_cnt, l_Height, l_Width: Integer;
   l_DataSet: TOracleDataSet;
   l_DataSource: TDataSource;
begin
   if not Assigned(frm_InputBox) then
      frm_InputBox := Tfrm_InputBox.Create(frm_InputBox);
   try
      with frm_InputBox do
      begin
         Caption := i_FormCaption;
         Width := i_FormWidth;
         l_comp := TLabel.Create(Self);
         TLabel(l_comp).Name := 'Lbl';
         TLabel(l_comp).Top := 19;
         TLabel(l_comp).Left := 5;
         TLabel(l_comp).Parent := pnValue;
         TLabel(l_comp).Caption := i_ValueCaption;
         l_Height := 130;
         l_Width  := TLabel(l_comp).Width + 5;

         if i_DataType = dtString then
         begin
            l_comp := TcxTextEdit.Create(Self);
            TcxTextEdit(l_comp).Name := 'edtValue';
            TcxTextEdit(l_comp).Top := 15;
            TcxTextEdit(l_comp).Left := l_Width;
            TcxTextEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxTextEdit(l_comp).Parent := pnValue;
            TcxTextEdit(l_comp).OnKeyDown := ValueKeyDown;
            TcxTextEdit(l_comp).Text := i_DefaultValue;
         end else
         if i_DataType = dtInteger then
         begin
            l_comp := TcxSpinEdit.Create(Self);
            TcxSpinEdit(l_comp).Name := 'edtValue';
            TcxSpinEdit(l_comp).Top := 15;
            TcxSpinEdit(l_comp).Left := l_Width;
            TcxSpinEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxSpinEdit(l_comp).Parent := pnValue;
            TcxSpinEdit(l_comp).OnKeyDown := ValueKeyDown;
            TcxSpinEdit(l_comp).Text := i_DefaultValue;
         end else
         if i_DataType = dtFloat then
         begin
            l_comp := TcxCurrencyEdit.Create(Self);
            TcxCurrencyEdit(l_comp).Name := 'edtValue';
            TcxCurrencyEdit(l_comp).Top := 15;
            TcxCurrencyEdit(l_comp).Left := l_Width;
            TcxCurrencyEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxCurrencyEdit(l_comp).Parent := pnValue;
            TcxCurrencyEdit(l_comp).OnKeyDown := ValueKeyDown;
            TcxCurrencyEdit(l_comp).Text := i_DefaultValue;
            TcxCurrencyEdit(l_comp).Properties.DisplayFormat := '';
            //TcxCurrencyEdit(l_comp).Properties.DisplayFormat := ',0.00';
         end else
         if i_DataType = dtDate then
         begin
            l_comp := TcxDateEdit.Create(Self);
            TcxDateEdit(l_comp).Name := 'edtValue';
            TcxDateEdit(l_comp).Top := 15;
            TcxDateEdit(l_comp).Left := l_Width;
            TcxDateEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxDateEdit(l_comp).Parent := pnValue;
            TcxDateEdit(l_comp).OnKeyDown := ValueKeyDown;
            if i_DefaultValue <> '' then
               TcxDateEdit(l_comp).Date := StrToDate(i_DefaultValue);
         end else
         if i_DataType = dtDateTime then
         begin
            l_comp := TcxDateEdit.Create(Self);
            TcxDateEdit(l_comp).Name := 'edtValue';
            TcxDateEdit(l_comp).Top := 15;
            TcxDateEdit(l_comp).Left := l_Width;
            TcxDateEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxDateEdit(l_comp).Parent := pnValue;
            TcxDateEdit(l_comp).OnKeyDown := ValueKeyDown;
            TcxDateEdit(l_comp).Properties.Kind := ckDateTime;
            TcxDateEdit(l_comp).Properties.DateButtons := [btnClear,btnNow,btnToday];
            if i_DefaultValue <> '' then
            begin
               try
                  TcxDateEdit(l_comp).Date := StrToDateTime(i_DefaultValue);
               except
                  TcxDateEdit(l_comp).Text := i_DefaultValue;
               end;
            end;
         end else
         if i_DataType = dtTime then
         begin
            l_comp := TcxTimeEdit.Create(Self);
            TcxTimeEdit(l_comp).Name := 'edtValue';
            TcxTimeEdit(l_comp).Top := 15;
            TcxTimeEdit(l_comp).Left := l_Width;
            TcxTimeEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxTimeEdit(l_comp).Parent := pnValue;
            TcxTimeEdit(l_comp).OnKeyDown := ValueKeyDown;
            if i_DefaultValue <> '' then
               TcxTimeEdit(l_comp).Time := StrToTime(i_DefaultValue);
         end else
         if i_DataType = dtLookup then
         begin
            l_comp := TcxComboBox.Create(Self);
            TcxComboBox(l_comp).Name := 'edtValue';
            TcxComboBox(l_comp).Top := 15;
            TcxComboBox(l_comp).Left := l_Width;
            TcxComboBox(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxComboBox(l_comp).Parent := pnValue;
            TcxComboBox(l_comp).OnKeyDown := ValueKeyDown;
            TcxComboBox(l_comp).Text := i_DefaultValue;
            l_tmp_str := i_DefaultValue;
            while  pos(';',l_tmp_str) > 0 do
            begin
               TcxComboBox(l_comp).Properties.Items.Add(Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1));
               Delete(l_tmp_str,1,pos(';',l_tmp_str));
            end;
            TcxComboBox(l_comp).ItemIndex := 0;
            TcxComboBox(l_comp).Properties.DropDownListStyle := lsFixedList;
         end else
         if i_DataType = dtDBLookup then
         begin
            l_DataSet := TOracleDataSet.create(Self);
            l_DataSource := TDataSource.Create(Self);
            l_DataSource.DataSet := l_DataSet;
            l_Sql := 'SELECT :I_KEY_VALUE ID, :I_DESCRIPTION DESCRIPTION FROM :I_TABLE_NAME WHERE :I_WHERE ';
            l_DataSet.Session := GFDataM.Get_Session;

            l_comp := TcxLookupComboBox.Create(Self);
            TcxLookupComboBox(l_comp).Name := 'edtValue';
            TcxLookupComboBox(l_comp).Top := 15;
            TcxLookupComboBox(l_comp).Left := l_Width;
            TcxLookupComboBox(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxLookupComboBox(l_comp).Parent := pnValue;
            TcxLookupComboBox(l_comp).OnKeyDown := ValueKeyDown;
            TcxLookupComboBox(l_comp).Properties.ListSource := l_DataSource;
            TcxLookupComboBox(l_comp).Properties.KeyFieldNames := 'ID';
            TcxLookupComboBox(l_comp).Properties.ListFieldNames := 'DESCRIPTION';
            TcxLookupComboBox(l_comp).Properties.ListOptions.ShowHeader := False;
            l_cnt := 0;
            l_tmp_str := i_DefaultValue;
            l_DataSet.Close;
            while  pos(';',l_tmp_str) > 0 do
            begin
               case l_cnt of
                  0: l_Sql := StringReplace(l_Sql,':I_TABLE_NAME',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                  1: l_Sql := StringReplace(l_Sql,':I_KEY_VALUE',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                  2: l_Sql := StringReplace(l_Sql,':I_DESCRIPTION',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                  3: begin
                        if Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1) <> '' then
                        begin
                           l_Sql := StringReplace(l_Sql,':I_WHERE',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                        end
                        else
                        begin
                           l_Sql := StringReplace(l_Sql,':I_WHERE','1=1',[rfReplaceAll]);
                        end;
                     end;
                  4: l_Default_Value := Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1);
               end;
               Delete(l_tmp_str,1,pos(';',l_tmp_str));
               l_cnt := l_cnt + 1;
            end;
            l_Sql := StringReplace(l_Sql,':I_WHERE','1=1',[rfReplaceAll]);
            l_DataSet.SQL.Text := l_Sql;
            l_DataSet.Open;
            if l_Default_Value <> '' then
            begin
               TcxLookupComboBox(l_comp).EditValue := l_Default_Value;
            end;
         end else
         if i_DataType = dtButtonEdit then
         begin
            l_comp := TcxButtonEdit.Create(Self);
            TcxButtonEdit(l_comp).Name := 'edtValue';
            TcxButtonEdit(l_comp).Top := 15;
            TcxButtonEdit(l_comp).Left := l_Width;
            TcxButtonEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxButtonEdit(l_comp).Parent := pnValue;
            TcxButtonEdit(l_comp).Text := '';
            TcxButtonEdit(l_comp).Properties.Buttons.Clear;
            TcxButtonEdit(l_comp).Properties.Buttons.Add;
            TcxButtonEdit(l_comp).Properties.Buttons[0].Kind := bkText;
            TcxButtonEdit(l_comp).Properties.Buttons[0].Caption := 'X';
            TcxButtonEdit(l_comp).Properties.Buttons.Add;
            TcxButtonEdit(l_comp).Properties.Buttons[1].Kind := bkText;
            TcxButtonEdit(l_comp).Properties.Buttons[1].Caption := 'L';
            TcxButtonEdit(l_comp).Properties.Nullstring := i_DefaultValue;
            TcxButtonEdit(l_comp).Properties.ReadOnly := True;
            TcxButtonEdit(l_comp).Properties.OnButtonClick := ButtonEditClik;
         end else
         if i_DataType = dtSpinEdit then
         begin
            l_Width := l_Width + 30;
            l_comp := TcxSpinEdit.Create(Self);
            TcxSpinEdit(l_comp).Name := 'edtValue';
            TcxSpinEdit(l_comp).Top := 15;
            TcxSpinEdit(l_comp).Left := l_Width;
            TcxSpinEdit(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxSpinEdit(l_comp).Parent := pnValue;
            TcxSpinEdit(l_comp).Value := i_DefaultValue;
         end else
         if i_DataType = dtcheckBox then
         begin
            l_Width := l_Width + 30;
            l_comp := TcxCheckBox.Create(Self);
            TcxCheckBox(l_comp).Name := 'edtValue';
            TcxCheckBox(l_comp).Top := 15;
            TcxCheckBox(l_comp).Left := l_Width;
            TcxCheckBox(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxCheckBox(l_comp).Parent := pnValue;
            TcxCheckBox(l_comp).checked := (i_DefaultValue = 'Y');
         end else
         if i_DataType = dtMemo then
         begin
            l_comp := TcxMemo.Create(Self);
            TcxMemo(l_comp).Name := 'edtValue';
            TcxMemo(l_comp).Top := 15;
            TcxMemo(l_comp).Left := l_Width;
            TcxMemo(l_comp).Width := pnValue.Width - (l_Width + 5);
            TcxMemo(l_comp).Parent := pnValue;
            //TcxMemo(l_comp).OnKeyDown := ValueKeyDown;
            TcxMemo(l_comp).Text := i_DefaultValue;
            TcxMemo(l_comp).Properties.ScrollBars := ssBoth;
            TcxMemo(l_comp).Height := 120;
            l_Height := 220;
         end;

         Height := l_Height;
         AutoSize := True;
         ShowModal;

         if ModalResult = mrOk then
         begin
            Result := True;
            if i_DataType = dtString then
            begin
               O_Result := TcxTextEdit(l_comp).Text;
            end else
            if i_DataType = dtInteger then
            begin
               O_Result := TcxSpinEdit(l_comp).Text;
            end else
            if i_DataType = dtFloat then
            begin
               O_Result := TcxCurrencyEdit(l_comp).Text;
            end else
            if i_DataType = dtDate then
            begin
               O_Result := TcxDateEdit(l_comp).Text;
            end else
            if i_DataType = dtDateTime then
            begin
               O_Result := TcxDateEdit(l_comp).Text;
            end else
            if i_DataType = dtTime then
            begin
               O_Result := TcxTimeEdit(l_comp).Text;
            end else
            if i_DataType = dtLookup then
            begin
               O_Result := TcxComboBox(l_comp).Text;
            end else
            if i_DataType = dtDBLookup then
            begin
               O_Result :=  VarToStrDef(TcxLookupComboBox(l_comp).EditValue,'');
            end else
            if i_DataType = dtButtonEdit then
            begin
               O_Result := TcxButtonEdit(l_comp).Hint;
            end else
            if i_DataType = dtSpinEdit then
            begin
               O_Result := TcxSpinEdit(l_comp).Text;
            end else
            if i_DataType = dtcheckBox then
            begin
              if TcxCheckBox(l_comp).Checked then
               O_Result := 'Y'
              else
               O_Result := 'N';
            end else
            if i_DataType = dtMemo then
            begin
               O_Result := TcxMemo(l_comp).Text;
            end;
         end else
         begin
            O_Result := '';
            Result := False;
         end;
      end;
   finally
      frm_InputBox.Free;
      frm_InputBox := nil;
   end;
end;


procedure Tfrm_InputBox.FormShow(Sender: TObject);
begin
  if Base_User_Info.Language = 'TR' then
  begin
    btnOk.Caption := 'Tamam';
    btnCancel.Caption := 'Çıkış';
  end
  else
  begin
    btnOk.Caption := 'Ok';
    btnCancel.Caption := 'Exit';
  end;
end;

function Tfrm_InputBox.InputBox(i_DataType: TInputDataType; i_ValueCaption: String = 'Değeri Giriniz'; i_FormCaption: String = 'Veri Giriş'; i_DefaultValue: String = ''; i_FormWidth: Integer = 500):String;
begin
   InputQuery(Result, i_DataType, i_ValueCaption, i_FormCaption, i_DefaultValue, i_FormWidth);
end;

procedure Tfrm_InputBox.ValueKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
   if Key = VK_Return then
   begin
      btnOk.Click;
   end else
   if Key = VK_ESCAPE then
   begin
      btnCancel.Click;
   end;
end;

procedure Tfrm_InputBox.ButtonEditClik(Sender: TObject; AButtonIndex: Integer);
var
   l_tmp_str : String;
   l_Count : Integer;
   l_Help: array [0..3] of String;
   SL_GET_VALUE: TStringList;
begin
   if AButtonIndex = 0 then
   begin
      TcxButtonEdit(Sender).Text := '';
      TcxButtonEdit(Sender).Hint := '';
   end else
   begin
      l_tmp_str := TcxButtonEdit(Sender).Properties.Nullstring;
      l_Count := 0;
      while  pos(';',l_tmp_str) > 0 do
      begin
         l_Help[l_Count] := Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1);
         Delete(l_tmp_str,1,pos(';',l_tmp_str));
         l_Count := l_Count + 1;
      end;

      try
         SL_GET_VALUE := TStringList.Create;
         Help_Create(l_Help[0],SL_GET_VALUE,l_Help[3],'',False);
         if SL_GET_VALUE.Count > 0 then
         begin
            TcxButtonEdit(Sender).Text := Get_SL_Value(SL_GET_VALUE,l_Help[2]);
            TcxButtonEdit(Sender).Hint := Get_SL_Value(SL_GET_VALUE,l_Help[1]);
         end;
      finally
         SL_GET_VALUE.Free;
      end;
   end;
end;

function Tfrm_InputBox.InputBoxMulti(
         i_DataType: array of TInputDataType;
         i_ValueCaption :array of String;
         i_DefaultValue: array of String;
         i_FormCaption: String;
         i_cancel_button_visible: boolean = True;
         i_FormWidth: Integer = 500;
         i_LabelWidth: Integer = 85): TStringArray;
begin
   InputBoxMultiQuery(Result, i_DataType,i_ValueCaption,i_DefaultValue,i_FormCaption,i_cancel_button_visible,i_FormWidth,i_LabelWidth);
end;

function Tfrm_InputBox.InputBoxMultiQuery(
         var O_Result: TStringArray;
         i_DataType: array of TInputDataType;
         i_ValueCaption :array of String;
         i_DefaultValue: array of String;
         i_FormCaption: String;
         i_cancel_button_visible: boolean = True;
         i_FormWidth: Integer = 500;
         i_LabelWidth: Integer = 85): Boolean;
var
   i, l_top, l_Count, l_MemoCnt, lpos: Integer;
   L_Height_Multiplier: Integer;
   l_comp: TComponent;
   l_result: TStringArray;
   l_tmp_str, l_Sql, l_Default_Value: String;
   l_DataSet: TOracleDataSet;
   l_DataSource: TDataSource;
   l_Comp_Array: Array of TComponent;
begin
   Result := False;

   if (Length(i_DataType) <> Length(i_ValueCaption)) or ( Length(i_DataType) <> Length(i_DefaultValue)) then
   begin
      Application.MessageBox('The number of data types, captions and default values must be the same','Error',MB_ICONSTOP);
      SetLength(l_result,Length(i_DataType));
      O_Result := l_result;
   end else
   begin
      try
         if not Assigned(frm_InputBox) then
            frm_InputBox := Tfrm_InputBox.Create(frm_InputBox);

         frm_InputBox.btnCancel.Visible := i_cancel_button_visible;

         with frm_InputBox do
         begin
            Caption := i_FormCaption;
            Width := i_FormWidth;

            l_MemoCnt := 0;
            L_Height_Multiplier := 0;
            for i:= 0 to Length(i_DataType) - 1 do
            begin
               {$REGION 'dtString'}
               if i_DataType[i] = dtString then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxTextEdit.Create(Self);
                  TcxTextEdit(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxTextEdit(l_comp).Top := l_top;
                  TcxTextEdit(l_comp).Left := i_LabelWidth;
                  TcxTextEdit(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxTextEdit(l_comp).Parent := pnValue;
                  TcxTextEdit(l_comp).OnKeyDown := ValueKeyDown;
                  TcxTextEdit(l_comp).Text := i_DefaultValue[i];
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtInteger'}
               if i_DataType[i] = dtInteger then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxSpinEdit.Create(Self);
                  TcxSpinEdit(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxSpinEdit(l_comp).Top := l_top;
                  TcxSpinEdit(l_comp).Left := i_LabelWidth;
                  TcxSpinEdit(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxSpinEdit(l_comp).Parent := pnValue;
                  TcxSpinEdit(l_comp).OnKeyDown := ValueKeyDown;
                  TcxSpinEdit(l_comp).Text := i_DefaultValue[i];
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtcheckBox'}
               if i_DataType[i] = dtcheckBox then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxcheckBox.Create(Self);
                  TcxcheckBox(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxcheckBox(l_comp).Top := l_top;
                  TcxcheckBox(l_comp).Left := i_LabelWidth;
                  TcxcheckBox(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxcheckBox(l_comp).Parent := pnValue;
                  TcxcheckBox(l_comp).Checked := (i_DefaultValue[i]= 'Y');
                  TcxcheckBox(l_comp).Caption := '';
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];

               end   else
               {$ENDREGION}
               {$REGION 'dtFloat'}
               if i_DataType[i] = dtFloat then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxCurrencyEdit.Create(Self);
                  TcxCurrencyEdit(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxCurrencyEdit(l_comp).Top := l_top;
                  TcxCurrencyEdit(l_comp).Left := i_LabelWidth;
                  TcxCurrencyEdit(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxCurrencyEdit(l_comp).Parent := pnValue;
                  TcxCurrencyEdit(l_comp).OnKeyDown := ValueKeyDown;
                  TcxCurrencyEdit(l_comp).Text := i_DefaultValue[i];
                  TcxCurrencyEdit(l_comp).Properties.DisplayFormat := '';
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtDate'}
               if i_DataType[i] = dtDate then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxDateEdit.Create(Self);
                  TcxDateEdit(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxDateEdit(l_comp).Top := l_top;
                  TcxDateEdit(l_comp).Left := i_LabelWidth;
                  TcxDateEdit(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxDateEdit(l_comp).Parent := pnValue;
                  TcxDateEdit(l_comp).OnKeyDown := ValueKeyDown;
                  TcxDateEdit(l_comp).Properties.DateButtons := [btnClear,btnToday];
                  if i_DefaultValue[i] <> '' then
                     TcxDateEdit(l_comp).Date := StrToDate(i_DefaultValue[i]);
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtDateTime'}
               if i_DataType[i] = dtDateTime then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxDateEdit.Create(Self);
                  TcxDateEdit(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxDateEdit(l_comp).Top := l_top;
                  TcxDateEdit(l_comp).Left := i_LabelWidth;
                  TcxDateEdit(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxDateEdit(l_comp).Parent := pnValue;
                  TcxDateEdit(l_comp).OnKeyDown := ValueKeyDown;
                  if i_DefaultValue[i] <> '' then
                  begin
                     try
                        TcxDateEdit(l_comp).Date := StrToDateTime(i_DefaultValue[i]);
                     except
                        TcxDateEdit(l_comp).Text := i_DefaultValue[i];
                     end;
                  end;
                  TcxDateEdit(l_comp).Properties.Kind := ckDateTime;
                  TcxDateEdit(l_comp).Properties.DateButtons := [btnClear,btnNow,btnToday];
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtTime'}
               if i_DataType[i] = dtTime then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxTimeEdit.Create(Self);
                  TcxDateEdit(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxTimeEdit(l_comp).Top := l_top;
                  TcxTimeEdit(l_comp).Left := i_LabelWidth;
                  TcxTimeEdit(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxTimeEdit(l_comp).Parent := pnValue;
                  TcxTimeEdit(l_comp).OnKeyDown := ValueKeyDown;
                  if i_DefaultValue[i] <> '' then
                     TcxTimeEdit(l_comp).EditValue := i_DefaultValue[i];
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtLookup'}
               if i_DataType[i] = dtLookup then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxComboBox.Create(Self);
                  TcxComboBox(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxComboBox(l_comp).Top := l_top;
                  TcxComboBox(l_comp).Left := i_LabelWidth;
                  TcxComboBox(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxComboBox(l_comp).Parent := pnValue;
                  TcxComboBox(l_comp).OnKeyDown := ValueKeyDown;
                  l_tmp_str := i_DefaultValue[i];
                  while  pos(';',l_tmp_str) > 0 do
                  begin
                     TcxComboBox(l_comp).Properties.Items.Add(Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1));
                     Delete(l_tmp_str,1,pos(';',l_tmp_str));
                  end;
                  TcxComboBox(l_comp).ItemIndex := 0;
                  TcxComboBox(l_comp).Properties.DropDownListStyle := lsFixedList;
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtDBLookup'}
               if i_DataType[i] = dtDBLookup then
               begin
                  l_DataSet := TOracleDataSet.create(Self);
                  TOracleDataSet(l_DataSet).Name := 'O_Data'+IntToStr(i);
                  l_DataSource := TDataSource.Create(Self);
                  TDataSource(l_DataSource).Name := 'SRC_Data'+IntToStr(i);
                  l_DataSource.DataSet := l_DataSet;
                  l_Sql := 'SELECT :I_KEY_VALUE ID, :I_DESCRIPTION DESCRIPTION FROM :I_TABLE_NAME WHERE :I_WHERE ';
                  l_DataSet.Session := GFDataM.Get_Session;

                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxLookupComboBox.Create(Self);
                  TcxLookupComboBox(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxLookupComboBox(l_comp).Top := l_top;
                  TcxLookupComboBox(l_comp).Left := i_LabelWidth;
                  TcxLookupComboBox(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxLookupComboBox(l_comp).Parent := pnValue;
                  TcxLookupComboBox(l_comp).Properties.ListSource := l_DataSource;
                  TcxLookupComboBox(l_comp).Properties.KeyFieldNames := 'ID';
                  TcxLookupComboBox(l_comp).Properties.ListFieldNames := 'DESCRIPTION';
                  TcxLookupComboBox(l_comp).Properties.ListOptions.ShowHeader := False;
                  l_Count := 0;
                  l_tmp_str := i_DefaultValue[i];
                  l_DataSet.Close;
                  while  pos(';',l_tmp_str) > 0 do
                  begin
                     //ShowMessage(inttostr(l_Count));
                     case l_Count of
                        0: l_Sql := StringReplace(l_Sql,':I_TABLE_NAME',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                        1: l_Sql := StringReplace(l_Sql,':I_KEY_VALUE',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                        2: l_Sql := StringReplace(l_Sql,':I_DESCRIPTION',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                        3: begin
                              if Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1) <> '' then
                              begin
                                 l_Sql := StringReplace(l_Sql,':I_WHERE',Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1),[rfReplaceAll]);
                              end
                              else
                              begin
                                 l_Sql := StringReplace(l_Sql,':I_WHERE','1=1',[rfReplaceAll]);
                              end;
                           end;
                        4: l_Default_Value := Copy(l_tmp_str,1,pos(';',l_tmp_str)- 1);
                     end;
                     //ShowMessage(l_tmp_str);
                     Delete(l_tmp_str,1,pos(';',l_tmp_str));
                     //ShowMessage(l_Default_Value);
                     l_Count := l_Count + 1;
                  end;

                  l_Sql := StringReplace(l_Sql,':I_WHERE','1=1',[rfReplaceAll]);
                  l_DataSet.SQL.Text := l_Sql;
                  l_DataSet.Open;
                  if l_Default_Value <> '' then
                  begin
                     TcxLookupComboBox(l_comp).EditValue := l_Default_Value;
                     TcxLookupComboBox(l_comp).Text := l_Default_Value;
                     l_Default_Value := '';
                  end;
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtButtonEdit'}
               if i_DataType[i] = dtButtonEdit then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxButtonEdit.Create(Self);
                  TcxButtonEdit(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxButtonEdit(l_comp).Top := l_top;
                  TcxButtonEdit(l_comp).Left := i_LabelWidth;
                  TcxButtonEdit(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxButtonEdit(l_comp).Parent := pnValue;
                  lpos := pos('|',i_DefaultValue[i]);
                  if lpos > 0 then
                  begin
                     TcxButtonEdit(l_comp).Text := Trim(copy(i_DefaultValue[i],lpos + 1,100));
                  end
                  else
                  begin
                     TcxButtonEdit(l_comp).Text := '';
                  end;

                  TcxButtonEdit(l_comp).Properties.Buttons.Clear;
                  TcxButtonEdit(l_comp).Properties.Buttons.Add;
                  TcxButtonEdit(l_comp).Properties.Buttons[0].Kind := bkText;
                  TcxButtonEdit(l_comp).Properties.Buttons[0].Caption := 'X';
                  TcxButtonEdit(l_comp).Properties.Buttons.Add;
                  TcxButtonEdit(l_comp).Properties.Buttons[1].Kind := bkText;
                  TcxButtonEdit(l_comp).Properties.Buttons[1].Caption := 'L';

                  if lpos > 0 then
                  begin
                     TcxButtonEdit(l_comp).Properties.Nullstring := Trim(copy(i_DefaultValue[i],lpos + 1,100));
                  end
                  else
                  begin
                     TcxButtonEdit(l_comp).Properties.Nullstring := i_DefaultValue[i];
                  end;

                  TcxButtonEdit(l_comp).Properties.ReadOnly := True;
                  TcxButtonEdit(l_comp).Properties.OnButtonClick := ButtonEditClik;
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
               end else
               {$ENDREGION}
               {$REGION 'dtMemo'}
               if i_DataType[i] = dtMemo then
               begin
                  SetLength(l_Comp_Array,i+1);
                  l_comp := TcxMemo.Create(Self);
                  TcxMemo(l_comp).Name := 'edtValue'+IntToStr(i);
                  l_top := 15 + (i*25) + (l_MemoCnt * 68);
                  TcxMemo(l_comp).Top := l_top;
                  TcxMemo(l_comp).Left := i_LabelWidth;
                  TcxMemo(l_comp).Width := pnValue.Width - i_LabelWidth - 5;
                  TcxMemo(l_comp).Parent := pnValue;
                  //TcxMemo(l_comp).OnKeyDown := ValueKeyDown;
                  TcxMemo(l_comp).Text := i_DefaultValue[i];
                  TcxMemo(l_comp).Properties.ScrollBars := ssBoth;
                  l_Comp_Array[i] := l_comp;

                  l_comp := TLabel.Create(Self);
                  TLabel(l_comp).Name := 'Lbl'+IntToStr(i);
                  TLabel(l_comp).Top := l_top + 4;
                  TLabel(l_comp).Left := 5;
                  TLabel(l_comp).Parent := pnValue;
                  TLabel(l_comp).Caption := i_ValueCaption[i];
                  l_MemoCnt := l_MemoCnt + 1;
               end;
                {$ENDREGION}
               L_Height_Multiplier := i;
            end;

            Height := 130 + (L_Height_Multiplier *26) + (l_MemoCnt * 68) ;
            AutoSize := True;
            if not i_cancel_button_visible then
            begin
               frm_InputBox.btnOk.Align := alRight;
            end;

            ShowModal;

            SetLength(l_result,Length(l_Comp_Array));

            for i := Low(l_Comp_Array) to High(l_Comp_Array) do
            begin
               if ModalResult = mrOk then
               begin
                  Result := True;

                  if l_Comp_Array[i] is TcxTextEdit then
                  begin
                     l_result[i] := TcxTextEdit(l_Comp_Array[i]).Text;
                  end else
                  if l_Comp_Array[i] is TcxSpinEdit then
                  begin
                     l_result[i] := TcxSpinEdit(l_Comp_Array[i]).Text;
                  end else
                  if l_Comp_Array[i] is TcxcheckBox then
                  begin
                    if TcxCheckBox(l_Comp_Array[i]).Checked then
                      l_result[i] := 'Y'
                    else
                      l_result[i] := 'N';
                  end else
                  if l_Comp_Array[i] is TcxCurrencyEdit then
                  begin
                     l_result[i] := TcxCurrencyEdit(l_Comp_Array[i]).Text;
                  end else
                  if l_Comp_Array[i] is TcxDateEdit then
                  begin
                     l_result[i] := TcxDateEdit(l_Comp_Array[i]).Text;
                  end else
                  if l_Comp_Array[i] is TcxTimeEdit then
                  begin
                     l_result[i] := TcxTimeEdit(l_Comp_Array[i]).Text;
                  end else
                  if l_Comp_Array[i] is TcxComboBox then
                  begin
                     l_result[i] := TcxComboBox(l_Comp_Array[i]).Text;
                  end else
                  if l_Comp_Array[i] is TcxLookupComboBox then
                  begin
                     if TcxLookupComboBox(l_Comp_Array[i]).Text <> '' then
                        l_result[i] := VarToStr(TcxLookupComboBox(l_Comp_Array[i]).EditValue)
                     else
                        l_result[i] := '';
                  end else
                  if l_Comp_Array[i] is TcxButtonEdit then
                  begin
                     l_result[i] := TcxButtonEdit(l_Comp_Array[i]).Hint;
                     if (lpos > 0) and (l_result[i] = '') then
                     begin
                        l_result[i] := Trim(copy(i_DefaultValue[i],lpos + 1,100));
                     end;
                  end else
                  if l_Comp_Array[i] is TcxMemo then
                  begin
                     l_result[i] := TcxMemo(l_Comp_Array[i]).Text;
                  end;
               end else
               begin
                  l_result[i] := '';
                  Result := False;
               end;
            end;
         end;

         O_Result := l_result;

      finally
         frm_InputBox.Free;
         frm_InputBox := nil;
      end;
   end;
end;

initialization
   RegisterClass(Tfrm_InputBox);

end.
