File: unit1.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 (132 lines) | stat: -rw-r--r-- 2,951 bytes parent folder | download | duplicates (8)
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
unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Grids, LR_DSet, LR_Class;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    frReport1: TfrReport;
    Filas: TfrUserDataset;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    StringGrid1: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FilasCheckEOF(Sender: TObject; var Eof: Boolean);
    procedure FilasFirst(Sender: TObject);
    procedure FilasNext(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure frReport1GetValue(const ParName: String; var ParValue: Variant);
  private
    fila : longint;
  public
    { public declarations }
  end; 

var
  Form1: TForm1; 

implementation

{$R unit1.lfm}

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
begin
  Edit1.Text := '';
  Edit2.Text := '';
  Edit3.Text := '';
  Edit4.Text := '';
  Edit5.Text := FormatFloat('###0.00', 0.0);
  
  StringGrid1.RowCount := 1;
  
  frReport1.LoadFromFile('sample.lrf');
  
  Edit1.SetFocus;
end;

procedure TForm1.frReport1GetValue(const ParName: String; var ParValue: Variant);
begin
  if ParName = 'cliente' then  // customer
    ParValue := Edit1.Text;
    
  if ParName = 'direccion' then  // address
    ParValue := Edit2.Text;
    
  if ParName = 'nombre' then // product
    ParValue := StringGrid1.Cells[0, fila];
    
  if ParName = 'precio' then // price
    ParValue := StringGrid1.Cells[1, fila];
    
  if ParName = 'total' then
    ParValue := '$ ' + Edit5.Text;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  StringGrid1.RowCount := StringGrid1.RowCount + 1;
  StringGrid1.Cells[0, StringGrid1.RowCount - 1] := Edit3.Text;
  StringGrid1.Cells[1, StringGrid1.RowCount - 1] := FormatFloat('$ ###0.00', StrToFloat(Edit4.Text));

  Edit5.Text := FormatFloat('###0.00', StrToFloat(Edit5.Text) + StrToFloat(Edit4.Text));
  
  Edit3.Text := '';
  Edit4.Text := '';
  
  Edit3.SetFocus;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  frReport1.DesignReport;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  frReport1.ShowReport
end;

procedure TForm1.FilasCheckEOF(Sender: TObject; var Eof: Boolean);
begin
  Eof := fila > StringGrid1.RowCount - 1;
end;

procedure TForm1.FilasFirst(Sender: TObject);
begin
  fila := 1; {fila por la cual empieza. En este caso la 1 porque la 0 es para los títulos}
             {starting row. In this case 1 because row 0 it's for title}
end;

procedure TForm1.FilasNext(Sender: TObject);
begin
  Inc(fila);
end;

end.