File: lr_fmted.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (206 lines) | stat: -rw-r--r-- 5,186 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

{*****************************************}
{                                         }
{             FastReport v2.3             }
{              Format editor              }
{                                         }
{  Copyright (c) 1998-99 by Tzyganenko A. }
{                                         }
{*****************************************}

unit LR_fmted;

interface

{$I LR_Vers.inc}

uses
  Classes, SysUtils, LResources,
  Forms, Controls, Graphics, Dialogs,
  Buttons, StdCtrls,ExtCtrls, ButtonPanel,LR_Class;

type

  { TfrFmtForm }

  TfrFmtForm = class(TForm)
    ButtonPanel1: TButtonPanel;
    GroupBox2: TGroupBox;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Panel1: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    SplEdit: TEdit;
    Panel2: TPanel;
    Edit1: TEdit;
    Label1: TLabel;
    Edit3: TEdit;
    procedure ComboBox2Select(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure SplEditEnter(Sender: TObject);
    procedure ShowPanel1;
    procedure ShowPanel2;
    procedure FormCreate(Sender: TObject);
    procedure frFmtFormShow(Sender: TObject);
  private
    fOldC1 : Integer;
    FFormat: Integer;
    FFormatStr:string;
    function GetFormat: Integer;
    function GetFormatStr: string;
    procedure SetFormat(const AValue: Integer);
    procedure SetFormatStr(const AValue: string);
  public
    { Public declarations }
    property EdFormat: Integer read GetFormat write SetFormat;
    property EdFormatStr:string read GetFormatStr write SetFormatStr;
  end;

var
  frFmtForm: TfrFmtForm;

implementation

{$R *.lfm}

uses LR_Const;

{$WARNINGS OFF}
procedure TfrFmtForm.ComboBox2Select(Sender: TObject);
begin
  ShowPanel2;
  ShowPanel1;
end;

procedure TfrFmtForm.ShowPanel1;
begin
  Panel1.Visible := (ComboBox1.ItemIndex = 1) and (not Panel2.Visible);
  if Panel1.Visible then
  begin
    Edit3.Text := IntToStr((FFormat and $0000FF00) div $00000100);
    SplEdit.Text := Chr(FFormat and $000000FF);
  end;
end;

procedure TfrFmtForm.ShowPanel2;
begin
  Panel2.Visible := ComboBox2.ItemIndex = 4;
end;

procedure TfrFmtForm.ComboBox1Change(Sender: TObject);
var
  k: Integer;
begin
  k := ComboBox1.ItemIndex;
  if (k = -1) or (k=fOldC1) then Exit;
  fOldC1:=k;
  ComboBox2.Items.Clear;
  Case k of
    fmtText   : ComboBox2.Items.Add(sFormat11);
    fmtNumber : begin
                  ComboBox2.Items.Add(sFormat21);
                  ComboBox2.Items.Add(sFormat22);
                  ComboBox2.Items.Add(sFormat23);
                  ComboBox2.Items.Add(sFormat24);
                  ComboBox2.Items.Add(sFormat25);
                end;
    fmtDate   : begin
                  ComboBox2.Items.Add(sFormat31);
                  ComboBox2.Items.Add(sFormat32);
                  ComboBox2.Items.Add(sFormat33);
                  ComboBox2.Items.Add(sFormat34);
                  ComboBox2.Items.Add(sFormat35);
                end;
    fmtTime   : begin
                  ComboBox2.Items.Add(sFormat41);
                  ComboBox2.Items.Add(sFormat42);
                  ComboBox2.Items.Add(sFormat43);
                  ComboBox2.Items.Add(sFormat44);
                  ComboBox2.Items.Add(sFormat45);
                end;
    fmtBoolean: begin
                  ComboBox2.Items.Add(sFormat51);
                  ComboBox2.Items.Add(sFormat52);
                  ComboBox2.Items.Add(sFormat53);
                  ComboBox2.Items.Add(sFormat54);
                  ComboBox2.Items.Add(sFormat55);
                end;
  end;

  ComboBox2.ItemIndex := 0;
  if Sender <> nil then
  begin
    ComboBox2Select(nil);
    ShowPanel1;
    Edit1.Text := '';
  end;
end;

procedure TfrFmtForm.SplEditEnter(Sender: TObject);
begin
  SplEdit.SelectAll;
end;
{$WARNINGS ON}

procedure TfrFmtForm.FormCreate(Sender: TObject);
begin
  fOldC1:=-1;
  Caption := sFmtFormFrmtVar;
  GroupBox2.Caption := sFmtFormVarFmt;
  Label5.Caption := sFmtFormDeciD;
  Label6.Caption := sFmtFormFrac;
  Label1.Caption := sFmtFormFrmt;
  SplEdit.Text := DefaultFormatSettings.DecimalSeparator;
end;

procedure TfrFmtForm.frFmtFormShow(Sender: TObject);
begin
  Panel1.Hide;
  Panel2.Hide;
  ComboBox1.Items.Clear;
  ComboBox1.Items.Add(sCateg1);
  ComboBox1.Items.Add(sCateg2);
  ComboBox1.Items.Add(sCateg3);
  ComboBox1.Items.Add(sCateg4);
  ComboBox1.Items.Add(sCateg5);

  ComboBox1.ItemIndex := (FFormat and $0F000000) div $01000000;
  ComboBox1Change(nil);
  ComboBox2.ItemIndex := (FFormat and $00FF0000) div $00010000;
  ShowPanel2;
  ShowPanel1;
end;

procedure TfrFmtForm.SetFormat(const AValue: Integer);
begin
  FFormat:=AValue;
end;

function TfrFmtForm.GetFormatStr: string;
begin
  if Edit1.Enabled then
    Result := Edit1.Text
  else
    Result := FFormatStr;
end;

procedure TfrFmtForm.SetFormatStr(const AValue: string);
begin
  FFormatStr:=AValue;
  Edit1.Text:=AValue;
end;

function TfrFmtForm.GetFormat: Integer;
var
  c: Char;
begin
  Result := ComboBox1.ItemIndex * $01000000 + ComboBox2.ItemIndex * $00010000 +
    StrToIntDef(Edit3.Text, 0) * $00000100;
  c := DefaultFormatSettings.DecimalSeparator;
  if SplEdit.Text <> '' then
    c := SplEdit.Text[1];
  Result := Result + Ord(c);
end;

end.