1 | unit ShowConstsU;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, StdCtrls, Buttons, ExtCtrls;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TConstantsOutputForm = class(TForm)
|
---|
11 | Panel1: TPanel;
|
---|
12 | ConstantsMemo: TMemo;
|
---|
13 | OpenButton: TBitBtn;
|
---|
14 | SaveButton: TBitBtn;
|
---|
15 | ClearButton: TBitBtn;
|
---|
16 | OKButton: TBitBtn;
|
---|
17 | OpenDialog1: TOpenDialog;
|
---|
18 | SaveDialog1: TSaveDialog;
|
---|
19 | SaveAsBitBtn: TBitBtn;
|
---|
20 | procedure OpenButtonClick(Sender: TObject);
|
---|
21 | procedure ClearButtonClick(Sender: TObject);
|
---|
22 | procedure SaveButtonClick(Sender: TObject);
|
---|
23 | procedure OKButtonClick(Sender: TObject);
|
---|
24 | procedure FormCreate(Sender: TObject);
|
---|
25 | procedure SaveAsBitBtnClick(Sender: TObject);
|
---|
26 | private
|
---|
27 | { Private declarations }
|
---|
28 | ConstantsText : AnsiString;
|
---|
29 | ConstantsFileName : string;
|
---|
30 | public
|
---|
31 | { Public declarations }
|
---|
32 | procedure AddConst(constSName,constStr : string);
|
---|
33 | function NeedsSave: boolean;
|
---|
34 | end;
|
---|
35 |
|
---|
36 | var
|
---|
37 | ConstantsOutputForm: TConstantsOutputForm;
|
---|
38 |
|
---|
39 | implementation
|
---|
40 |
|
---|
41 | {$R *.dfm}
|
---|
42 |
|
---|
43 | procedure TConstantsOutputForm.OpenButtonClick(Sender: TObject);
|
---|
44 | begin
|
---|
45 | //CHANGE--first ask user "SURE?"
|
---|
46 | if OpenDialog1.Execute then begin
|
---|
47 | ConstantsFileName := OpenDialog1.FileName;
|
---|
48 | ConstantsMemo.Lines.LoadFromFile(ConstantsFileName);
|
---|
49 | end;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | procedure TConstantsOutputForm.ClearButtonClick(Sender: TObject);
|
---|
53 | var choice : integer;
|
---|
54 | begin
|
---|
55 | choice := mrYes;
|
---|
56 | if NeedsSave then choice := MessageDlg('Clear Current Constants? (This can not be undone.)',
|
---|
57 | mtConfirmation, [mbYes,mbNo,mbCancel], 0);
|
---|
58 | if choice=mrYes then ConstantsMemo.Lines.Clear;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | procedure TConstantsOutputForm.SaveButtonClick(Sender: TObject);
|
---|
62 | begin
|
---|
63 | if ConstantsFileName <> '' then ConstantsMemo.Lines.SaveToFile(ConstantsFileName);
|
---|
64 | ConstantsText:=ConstantsMemo.Text; // tracks if save needed.
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TConstantsOutputForm.SaveAsBitBtnClick(Sender: TObject);
|
---|
68 | begin
|
---|
69 | if SaveDialog1.Execute then begin
|
---|
70 | ConstantsFileName := SaveDialog1.FileName;
|
---|
71 | ConstantsMemo.Lines.SaveToFile(ConstantsFileName);
|
---|
72 | ConstantsText:=ConstantsMemo.Text; // tracks if save needed.
|
---|
73 | end;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | procedure TConstantsOutputForm.OKButtonClick(Sender: TObject);
|
---|
77 | begin
|
---|
78 | ConstantsOutputForm.Hide;
|
---|
79 | end;
|
---|
80 |
|
---|
81 |
|
---|
82 | procedure TConstantsOutputForm.AddConst(constSName,constStr : string);
|
---|
83 | var tempS : string;
|
---|
84 | begin
|
---|
85 | tempS := constSName+'='+constStr;
|
---|
86 | if ConstantsMemo.Lines.IndexOf(tempS)<0 then begin
|
---|
87 | ConstantsMemo.Lines.Add(tempS);
|
---|
88 | end;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | function TConstantsOutputForm.NeedsSave: boolean;
|
---|
92 | begin
|
---|
93 | Result := ConstantsMemo.Modified;
|
---|
94 | //Result := (ConstantsText=ConstantsMemo.Text);
|
---|
95 | end;
|
---|
96 |
|
---|
97 |
|
---|
98 | procedure TConstantsOutputForm.FormCreate(Sender: TObject);
|
---|
99 | var choice: integer;
|
---|
100 | begin
|
---|
101 | choice := MessageDlg('Open Existing Constants File?', mtCustom, [mbYes,mbNo], 0);
|
---|
102 | if choice=mrYes then OpenButtonClick(Sender);
|
---|
103 | end;
|
---|
104 |
|
---|
105 |
|
---|
106 | end.
|
---|