unit MergeTextFrm;

interface

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

type
  TMergeTextForm = class(TForm)
    lePreText: TLabeledEdit;
    lePhaseIndex: TLabeledEdit;
    leNumber: TLabeledEdit;
    btnOk: TButton;
    btnCancel: TButton;
  private
    function GetMergeText: string;
    procedure SetMergeText(const Value: string);
  public
    property MergeText: string read GetMergeText write SetMergeText;
  end;

function GetMergeText(const ATitle: string; var AText: string): Boolean;

implementation

{$R *.dfm}

function GetMergeText(const ATitle: string; var AText: string): Boolean;
var
  MergeTextForm: TMergeTextForm;
begin
  MergeTextForm := TMergeTextForm.Create(nil);
  try
    MergeTextForm.MergeText := AText;
    if MergeTextForm.ShowModal = mrOk then
    begin
      Result := True;
      AText := MergeTextForm.MergeText;
    end
    else Result := False;
  finally
    MergeTextForm.Free;
  end;
end;

{ TMergeTextForm }

function TMergeTextForm.GetMergeText: string;
begin
  Result := lePreText.Text + '-' + lePhaseIndex.Text + '-' + leNumber.Text;
end;

procedure TMergeTextForm.SetMergeText(const Value: string);
var
  sgs: TStringList;
begin
  sgs := TStringList.Create;
  try
    sgs.Delimiter := '-';
    sgs.DelimitedText := Value;
    lePreText.Text := sgs.Strings[0];
    lePhaseIndex.Text := sgs.Strings[1];
    leNumber.Text := sgs.Strings[2];
  finally
    sgs.Free;
  end;
end;

end.
