tvplanit: Improve usability and avoid crashes in PrintFormat element editor.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8532 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-10-10 22:53:19 +00:00
parent 7d24ff5ac1
commit 2688b61c26
2 changed files with 167 additions and 132 deletions

View File

@ -2,14 +2,14 @@ object frmEditElement: TfrmEditElement
Left = 288 Left = 288
Height = 446 Height = 446
Top = 321 Top = 321
Width = 455 Width = 487
HorzScrollBar.Page = 378 HorzScrollBar.Page = 378
VertScrollBar.Page = 444 VertScrollBar.Page = 444
AutoSize = True AutoSize = True
BorderStyle = bsDialog BorderStyle = bsDialog
Caption = 'Edit Element' Caption = 'Edit Element'
ClientHeight = 446 ClientHeight = 446
ClientWidth = 455 ClientWidth = 487
OnCreate = FormCreate OnCreate = FormCreate
OnShow = FormShow OnShow = FormShow
Position = poScreenCenter Position = poScreenCenter
@ -17,7 +17,7 @@ object frmEditElement: TfrmEditElement
Left = 12 Left = 12
Height = 54 Height = 54
Top = 351 Top = 351
Width = 431 Width = 463
Align = alTop Align = alTop
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 12
@ -26,7 +26,7 @@ object frmEditElement: TfrmEditElement
BorderSpacing.Bottom = 6 BorderSpacing.Bottom = 6
Caption = ' Caption ' Caption = ' Caption '
ClientHeight = 34 ClientHeight = 34
ClientWidth = 427 ClientWidth = 459
Font.Style = [fsBold] Font.Style = [fsBold]
ParentFont = False ParentFont = False
TabOrder = 4 TabOrder = 4
@ -50,7 +50,7 @@ object frmEditElement: TfrmEditElement
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = gbCaption AnchorSideRight.Control = gbCaption
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 360 Left = 392
Height = 25 Height = 25
Top = 1 Top = 1
Width = 59 Width = 59
@ -70,7 +70,7 @@ object frmEditElement: TfrmEditElement
Left = 43 Left = 43
Height = 23 Height = 23
Top = 2 Top = 2
Width = 313 Width = 345
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 2 BorderSpacing.Top = 2
@ -85,7 +85,7 @@ object frmEditElement: TfrmEditElement
Left = 12 Left = 12
Height = 23 Height = 23
Top = 8 Top = 8
Width = 431 Width = 463
Align = alTop Align = alTop
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 12
@ -94,7 +94,7 @@ object frmEditElement: TfrmEditElement
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 23 ClientHeight = 23
ClientWidth = 431 ClientWidth = 463
TabOrder = 0 TabOrder = 0
object lblName: TLabel object lblName: TLabel
AnchorSideTop.Control = edName AnchorSideTop.Control = edName
@ -113,7 +113,7 @@ object frmEditElement: TfrmEditElement
Left = 42 Left = 42
Height = 23 Height = 23
Top = 0 Top = 0
Width = 389 Width = 421
Align = alRight Align = alRight
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 4 BorderSpacing.Left = 4
@ -124,7 +124,7 @@ object frmEditElement: TfrmEditElement
Left = 12 Left = 12
Height = 51 Height = 51
Top = 152 Top = 152
Width = 433 Width = 465
Align = alTop Align = alTop
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 12
@ -132,7 +132,7 @@ object frmEditElement: TfrmEditElement
BorderSpacing.Right = 10 BorderSpacing.Right = 10
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 51 ClientHeight = 51
ClientWidth = 433 ClientWidth = 465
TabOrder = 2 TabOrder = 2
object gbDayOffset: TGroupBox object gbDayOffset: TGroupBox
AnchorSideTop.Control = DayOffsetPanel AnchorSideTop.Control = DayOffsetPanel
@ -190,7 +190,7 @@ object frmEditElement: TfrmEditElement
Left = 112 Left = 112
Height = 51 Height = 51
Top = 0 Top = 0
Width = 321 Width = 353
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoFill = True AutoFill = True
AutoSize = True AutoSize = True
@ -205,7 +205,7 @@ object frmEditElement: TfrmEditElement
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 4 ChildSizing.ControlsPerLine = 4
ClientHeight = 31 ClientHeight = 31
ClientWidth = 317 ClientWidth = 349
Columns = 4 Columns = 4
ItemIndex = 0 ItemIndex = 0
Items.Strings = ( Items.Strings = (
@ -222,7 +222,7 @@ object frmEditElement: TfrmEditElement
Left = 12 Left = 12
Height = 25 Height = 25
Top = 413 Top = 413
Width = 431 Width = 463
Align = alTop Align = alTop
BorderSpacing.Left = 12 BorderSpacing.Left = 12
BorderSpacing.Top = 8 BorderSpacing.Top = 8
@ -230,7 +230,7 @@ object frmEditElement: TfrmEditElement
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 25 ClientHeight = 25
ClientWidth = 431 ClientWidth = 463
TabOrder = 5 TabOrder = 5
object btnShape: TButton object btnShape: TButton
Left = 0 Left = 0
@ -245,7 +245,7 @@ object frmEditElement: TfrmEditElement
TabOrder = 0 TabOrder = 0
end end
object btnOk: TButton object btnOk: TButton
Left = 323 Left = 355
Height = 25 Height = 25
Top = 0 Top = 0
Width = 42 Width = 42
@ -257,7 +257,7 @@ object frmEditElement: TfrmEditElement
TabOrder = 1 TabOrder = 1
end end
object btnCancel: TButton object btnCancel: TButton
Left = 369 Left = 401
Height = 25 Height = 25
Top = 0 Top = 0
Width = 62 Width = 62
@ -272,7 +272,7 @@ object frmEditElement: TfrmEditElement
Left = 12 Left = 12
Height = 97 Height = 97
Top = 43 Top = 43
Width = 433 Width = 465
Align = alTop Align = alTop
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 12
@ -280,13 +280,13 @@ object frmEditElement: TfrmEditElement
BorderSpacing.Right = 10 BorderSpacing.Right = 10
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 97 ClientHeight = 97
ClientWidth = 433 ClientWidth = 465
TabOrder = 1 TabOrder = 1
object rgItemType: TRadioGroup object rgItemType: TRadioGroup
Left = 0 Left = 0
Height = 97 Height = 97
Top = 0 Top = 0
Width = 433 Width = 465
Align = alClient Align = alClient
AutoFill = True AutoFill = True
BorderSpacing.InnerBorder = 4 BorderSpacing.InnerBorder = 4
@ -300,7 +300,7 @@ object frmEditElement: TfrmEditElement
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3 ChildSizing.ControlsPerLine = 3
ClientHeight = 77 ClientHeight = 77
ClientWidth = 429 ClientWidth = 461
Columns = 3 Columns = 3
ItemIndex = 0 ItemIndex = 0
Items.Strings = ( Items.Strings = (
@ -323,14 +323,14 @@ object frmEditElement: TfrmEditElement
Left = 12 Left = 12
Height = 124 Height = 124
Top = 215 Top = 215
Width = 443 Width = 475
Align = alTop Align = alTop
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 12
BorderSpacing.Top = 12 BorderSpacing.Top = 12
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 124 ClientHeight = 124
ClientWidth = 443 ClientWidth = 475
TabOrder = 3 TabOrder = 3
object rgRotation: TRadioGroup object rgRotation: TRadioGroup
AnchorSideLeft.Control = PositionPanel AnchorSideLeft.Control = PositionPanel
@ -373,28 +373,28 @@ object frmEditElement: TfrmEditElement
Left = 101 Left = 101
Height = 116 Height = 116
Top = 0 Top = 0
Width = 330 Width = 362
Anchors = [akTop, akLeft, akBottom] Anchors = [akTop, akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 16 BorderSpacing.Left = 16
BorderSpacing.Right = 12 BorderSpacing.Right = 12
Caption = 'Position' Caption = 'Position'
ClientHeight = 96 ClientHeight = 96
ClientWidth = 326 ClientWidth = 358
TabOrder = 1 TabOrder = 1
object TopLeftPanel: TPanel object TopLeftPanel: TPanel
AnchorSideLeft.Control = gbPosition AnchorSideLeft.Control = gbPosition
AnchorSideTop.Control = gbPosition AnchorSideTop.Control = gbPosition
Left = 16 Left = 16
Height = 54 Height = 55
Top = 4 Top = 4
Width = 92 Width = 104
AutoSize = True AutoSize = True
BorderSpacing.Left = 16 BorderSpacing.Left = 16
BorderSpacing.Top = 4 BorderSpacing.Top = 4
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 54 ClientHeight = 55
ClientWidth = 92 ClientWidth = 104
ParentFont = False ParentFont = False
TabOrder = 0 TabOrder = 0
object BevelTopLeft: TBevel object BevelTopLeft: TBevel
@ -402,10 +402,10 @@ object frmEditElement: TfrmEditElement
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = TopLeftPanel AnchorSideRight.Control = TopLeftPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 0 Left = 32
Height = 8 Height = 8
Top = 23 Top = 23
Width = 92 Width = 72
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
end end
object LblTop: TLabel object LblTop: TLabel
@ -430,7 +430,8 @@ object frmEditElement: TfrmEditElement
Left = 32 Left = 32
Height = 23 Height = 23
Top = 0 Top = 0
Width = 48 Width = 60
Alignment = taRightJustify
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
OnEnter = PosEditEnter OnEnter = PosEditEnter
OnExit = PosEditExit OnExit = PosEditExit
@ -442,7 +443,7 @@ object frmEditElement: TfrmEditElement
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = TopLeftPanel AnchorSideRight.Control = TopLeftPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 80 Left = 92
Height = 23 Height = 23
Top = 0 Top = 0
Width = 12 Width = 12
@ -459,9 +460,9 @@ object frmEditElement: TfrmEditElement
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = TopLeftPanel AnchorSideRight.Control = TopLeftPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 80 Left = 92
Height = 23 Height = 23
Top = 31 Top = 32
Width = 12 Width = 12
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
Associate = edLeft Associate = edLeft
@ -471,12 +472,14 @@ object frmEditElement: TfrmEditElement
TabOrder = 3 TabOrder = 3
end end
object edLeft: TEdit object edLeft: TEdit
AnchorSideLeft.Control = edTop
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = udLeft AnchorSideRight.Control = udLeft
Left = 32 Left = 32
Height = 23 Height = 23
Top = 31 Top = 32
Width = 48 Width = 60
Alignment = taRightJustify
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
OnEnter = PosEditEnter OnEnter = PosEditEnter
OnExit = PosEditExit OnExit = PosEditExit
@ -489,7 +492,7 @@ object frmEditElement: TfrmEditElement
AnchorSideRight.Control = edLeft AnchorSideRight.Control = edLeft
Left = 1 Left = 1
Height = 15 Height = 15
Top = 35 Top = 36
Width = 23 Width = 23
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Left = 1 BorderSpacing.Left = 1
@ -505,16 +508,16 @@ object frmEditElement: TfrmEditElement
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = TopLeftPanel AnchorSideTop.Control = TopLeftPanel
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 124 Left = 136
Height = 54 Height = 54
Top = 4 Top = 4
Width = 99 Width = 119
AutoSize = True AutoSize = True
BorderSpacing.Left = 16 BorderSpacing.Left = 16
BorderSpacing.Right = 12 BorderSpacing.Right = 12
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 54 ClientHeight = 54
ClientWidth = 99 ClientWidth = 119
ParentFont = False ParentFont = False
TabOrder = 1 TabOrder = 1
object LblHeight: TLabel object LblHeight: TLabel
@ -540,7 +543,8 @@ object frmEditElement: TfrmEditElement
Left = 47 Left = 47
Height = 23 Height = 23
Top = 0 Top = 0
Width = 40 Width = 60
Alignment = taRightJustify
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
OnEnter = PosEditEnter OnEnter = PosEditEnter
OnExit = PosEditExit OnExit = PosEditExit
@ -552,7 +556,7 @@ object frmEditElement: TfrmEditElement
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = HeightWidthPanel AnchorSideRight.Control = HeightWidthPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 87 Left = 107
Height = 23 Height = 23
Top = 0 Top = 0
Width = 12 Width = 12
@ -585,7 +589,8 @@ object frmEditElement: TfrmEditElement
Left = 47 Left = 47
Height = 23 Height = 23
Top = 31 Top = 31
Width = 40 Width = 60
Alignment = taRightJustify
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
OnEnter = PosEditEnter OnEnter = PosEditEnter
OnExit = PosEditExit OnExit = PosEditExit
@ -597,7 +602,7 @@ object frmEditElement: TfrmEditElement
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = HeightWidthPanel AnchorSideRight.Control = HeightWidthPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 87 Left = 107
Height = 23 Height = 23
Top = 31 Top = 31
Width = 12 Width = 12
@ -617,7 +622,7 @@ object frmEditElement: TfrmEditElement
Left = 0 Left = 0
Height = 8 Height = 8
Top = 23 Top = 23
Width = 99 Width = 119
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
end end
end end
@ -628,7 +633,7 @@ object frmEditElement: TfrmEditElement
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = gbPosition AnchorSideBottom.Control = gbPosition
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 93 Left = 109
Height = 19 Height = 19
Top = 73 Top = 73
Width = 52 Width = 52
@ -644,7 +649,7 @@ object frmEditElement: TfrmEditElement
AnchorSideTop.Control = gbPosition AnchorSideTop.Control = gbPosition
AnchorSideBottom.Control = gbPosition AnchorSideBottom.Control = gbPosition
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 255 Left = 287
Height = 94 Height = 94
Top = 0 Top = 0
Width = 59 Width = 59
@ -709,7 +714,7 @@ object frmEditElement: TfrmEditElement
Left = 16 Left = 16
Height = 8 Height = 8
Top = 64 Top = 64
Width = 207 Width = 239
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
Shape = bsSpacer Shape = bsSpacer
end end

View File

@ -201,7 +201,7 @@ end;
procedure TfrmPrnFormat.btnDeleteElementClick(Sender: TObject); procedure TfrmPrnFormat.btnDeleteElementClick(Sender: TObject);
var var
Format: TVpPrintFormatItem; Format: TVpPrintFormatItem;
Idx: Integer; i, idx, n: Integer;
Item: string; Item: string;
begin begin
Format := TVpPrintFormatItem(lbFormats.Items.Objects[lbFormats.ItemIndex]); Format := TVpPrintFormatItem(lbFormats.Items.Objects[lbFormats.ItemIndex]);
@ -210,30 +210,54 @@ begin
Item := lbElements.Items[lbElements.ItemIndex]; Item := lbElements.Items[lbElements.ItemIndex];
if Item <> '' then begin if Item <> '' then begin
for Idx := Pred(Format.Elements.Count) downto 0 do begin n := Format.Elements.Count;
if Format.Elements.Items[Idx].ElementName = Item then begin idx := lbElements.ItemIndex;
Format.Elements.Items[Idx].Free; for i := n-1 downto 0 do begin
if Format.Elements.Items[i].ElementName = Item then begin
Format.Elements.Items[i].Free;
lbElements.Items.Delete(lbElements.ItemIndex); lbElements.Items.Delete(lbElements.ItemIndex);
IsDirty := True; if idx = lbElements.Items.Count then
idx := lbElements.Items.Count-1;
lbElements.ItemIndex := idx;
UpdatePreview; UpdatePreview;
IsDirty := True;
Break;
end; end;
end; end;
end; end;
EnableElementButtons(true);
end; end;
procedure TfrmPrnFormat.btnDeleteFormatClick(Sender: TObject); procedure TfrmPrnFormat.btnDeleteFormatClick(Sender: TObject);
var var
Prn: TVpPrinter; Prn: TVpPrinter;
Idx: Integer; Idx, fmtIdx: Integer;
begin begin
Prn := ControlLink.Printer; Prn := ControlLink.Printer;
Idx := Prn.Find(lbFormats.Items[lbFormats.ItemIndex]); Idx := lbFormats.ItemIndex;
if (Idx < 0) or (Idx >= Prn.PrintFormats.Count) then fmtIdx := Prn.Find(lbFormats.Items[idx]);
if (fmtIdx < 0) or (fmtIdx >= Prn.PrintFormats.Count) then
begin
ShowMessage ('Invalid print format: ' + lbFormats.Items[lbFormats.ItemIndex]); ShowMessage ('Invalid print format: ' + lbFormats.Items[lbFormats.ItemIndex]);
Prn.PrintFormats.Items[Idx].Free; exit;
lbFormats.Items.Delete(lbFormats.ItemIndex); end;
Prn.PrintFormats.Items[FmtIdx].Free;
lbElements.Items.Clear;
lbFormats.Items.Delete(idx);
IsDirty := True; IsDirty := True;
UpdatePreview; if idx = lbFormats.Items.Count then
idx := lbFormats.Items.Count-1;
if idx >= 0 then
begin
lbFormats.ItemIndex := idx;
fmtIdx := Prn.Find(lbFormats.Items[idx]);
Prn.CurFormat := fmtIdx;
UpdatePreview;
end else
; // to do: clear preview
EnableFormatButtons(true);
EnableElementButtons(true);
end; end;
procedure TfrmPrnFormat.btnEditElementClick(Sender: TObject); procedure TfrmPrnFormat.btnEditElementClick(Sender: TObject);
@ -303,8 +327,8 @@ var
i: Integer; i: Integer;
begin begin
NewFormatIdx := DoNewFormat; NewFormatIdx := DoNewFormat;
if (NewFormatIdx > 0) and (Assigned (ControlLink)) and if Assigned(ControlLink) and
(NewFormatIdx < ControlLink.Printer.PrintFormats.Count) (NewFormatIdx > 0) and (NewFormatIdx < ControlLink.Printer.PrintFormats.Count)
then then
for i := 0 to lbFormats.Items.Count - 1 do for i := 0 to lbFormats.Items.Count - 1 do
if lbFormats.Items[i] = ControlLink.Printer.PrintFormats.Items[NewFormatIdx].FormatName then if lbFormats.Items[i] = ControlLink.Printer.PrintFormats.Items[NewFormatIdx].FormatName then
@ -364,16 +388,15 @@ var
frmEditElement: TfrmEditElement; frmEditElement: TfrmEditElement;
begin begin
if lbElements.ItemIndex > -1 then begin if lbElements.ItemIndex > -1 then begin
Application.CreateForm(TfrmEditElement, frmEditElement); frmEditElement := TfrmEditElement.Create(nil);
try
E := TVpPrintFormatElementItem(lbElements.Items.Objects[lbElements.ItemIndex]); E := TVpPrintFormatElementItem(lbElements.Items.Objects[lbElements.ItemIndex]);
if frmEditElement.Execute(E) then begin if frmEditElement.Execute(E) then
IsDirty := True; IsDirty := True;
UpdatePreview;
finally
frmEditElement.Free;
end; end;
frmEditElement.Free;
UpdatePreview;
end end
else begin else begin
DoNewElement; DoNewElement;
@ -419,36 +442,39 @@ begin
Unique := False; Unique := False;
Application.CreateForm(TfrmEditElement, frmEditElement); frmEditElement := TfrmEditElement.Create(nil);
try
repeat
E := TVpPrintFormatElementItem.Create(Format.Elements);
repeat // Edit element
E := TVpPrintFormatElementItem.Create(Format.Elements); Cancelled := not frmEditElement.Execute(E);
{ edit Element } if not Cancelled then begin
Cancelled := not frmEditElement.Execute(E); if lbElements.Items.IndexOf(E.ElementName) > -1 then begin
ShowMessage('An Element named ' + E.ElementName + ' already exists.' +
if not Cancelled then begin #13#10 + 'Please use another name.');
if lbElements.Items.IndexOf(E.ElementName) > -1 then begin // Dump empty element
ShowMessage('An Element named ' + E.ElementName + ' already exists.' + Format.Elements.Items[E.Index].Free;
#13#10 + 'Please use another name.'); Unique := False;
{ dump empty element } end
else begin
lbElements.Items.AddObject(E.ElementName, E);
lbElements.ItemIndex := E.Index;
IsDirty := True;
Unique := True;
UpdatePreview;
end;
end else
// Dump empty element
Format.Elements.Items[E.Index].Free; Format.Elements.Items[E.Index].Free;
Unique := False; // ...until element name is Unique or operation is cancelled
end until Unique or Cancelled;
else begin
lbElements.Items.AddObject(E.ElementName, E);
lbElements.ItemIndex := E.Index;
IsDirty := True;
Unique := True;
UpdatePreview;
end;
end else
{ dump empty element }
Format.Elements.Items[E.Index].Free;
{ until element name is Unique or operation Cancelled }
until Unique or Cancelled;
frmEditElement.Free; EnableElementButtons(true);
finally
frmEditElement.Free;
end;
end; end;
procedure TfrmPrnFormat.DoNewFile; procedure TfrmPrnFormat.DoNewFile;
@ -475,40 +501,44 @@ var
frmEditFormat: TfrmEditFormat; frmEditFormat: TfrmEditFormat;
begin begin
Result := -1; Result := -1;
Application.CreateForm(TfrmEditFormat, frmEditFormat); frmEditFormat := TfrmEditFormat.Create(nil);
try
Prn := ControlLink.Printer;
Unique := False;
repeat
AFormat := TVpPrintFormatItem.Create(Prn.PrintFormats);
// Edit format
Cancelled := not frmEditFormat.Execute(AFormat);
Prn := ControlLink.Printer; if not Cancelled then begin
Unique := False; if lbFormats.Items.IndexOf(AFormat.FormatName) > -1 then begin
repeat ShowMessage('A format named ' + AFormat.FormatName + ' already exists.' +
AFormat := TVpPrintFormatItem.Create(Prn.PrintFormats); #13#10 + 'Please use another name.');
{ edit format } // Dump empty format
Cancelled := not frmEditFormat.Execute(AFormat); Prn.PrintFormats.Items[AFormat.Index].Free;
Unique := False;
if not Cancelled then begin end
if lbFormats.Items.IndexOf(AFormat.FormatName) > -1 then begin else begin
ShowMessage('A format named ' + AFormat.FormatName + ' already exists.' + lbFormats.Items.AddObject(AFormat.FormatName, AFormat);
#13#10 + 'Please use another name.'); lbFormats.ItemIndex := AFormat.Index;
{ dump empty format } UpdatePreview;
IsDirty := True;
Unique := True;
end;
end else
// Dump empty format
Prn.PrintFormats.Items[AFormat.Index].Free; Prn.PrintFormats.Items[AFormat.Index].Free;
Unique := False; // ... until format name is Unique or operation cancelled
end until Unique or Cancelled;
else begin
lbFormats.Items.AddObject(AFormat.FormatName, AFormat);
lbFormats.ItemIndex := AFormat.Index;
UpdatePreview;
IsDirty := True;
Unique := True;
end;
end else
{ dump empty format }
Prn.PrintFormats.Items[AFormat.Index].Free;
{ until format name is Unique or operation Cancelled }
until Unique or Cancelled;
if not Cancelled then if not Cancelled then
Result := AFormat.Index; Result := AFormat.Index;
frmEditFormat.Free; EnableFormatButtons(true);
EnableElementButtons(true);
finally
frmEditFormat.Free;
end;
end; end;
procedure TfrmPrnFormat.DoSave; procedure TfrmPrnFormat.DoSave;
@ -527,17 +557,17 @@ end;
procedure TfrmPrnFormat.EnableElementButtons(Enable: Boolean); procedure TfrmPrnFormat.EnableElementButtons(Enable: Boolean);
begin begin
btnNewElement.Enabled := Enable; btnNewElement.Enabled := Enable and (lbFormats.ItemIndex > -1);
btnEditElement.Enabled := Enable; btnEditElement.Enabled := btnNewElement.Enabled and (lbElements.ItemIndex > -1);
btnDeleteElement.Enabled := Enable; btnDeleteElement.Enabled := btnEditElement.Enabled;
EnableMoveButtons; EnableMoveButtons;
end; end;
procedure TfrmPrnFormat.EnableFormatButtons(Enable: Boolean); procedure TfrmPrnFormat.EnableFormatButtons(Enable: Boolean);
begin begin
btnNewFormat.Enabled := Enable; btnNewFormat.Enabled := Enable;
btnEditFormat.Enabled := Enable; btnEditFormat.Enabled := Enable and (lbFormats.ItemIndex > -1);
btnDeleteFormat.Enabled := Enable; btnDeleteFormat.Enabled := Enable and (lbFormats.ItemIndex > -1);
end; end;
function TfrmPrnFormat.Execute: Boolean; function TfrmPrnFormat.Execute: Boolean;