File: lrtdbfdata.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 (158 lines) | stat: -rw-r--r-- 3,771 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
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
unit lrTDbfData;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Graphics, LR_Class, LR_DBComponent, DB, dbf;

type
  TlrTDbfData = class(TComponent)
  end;

type

  { TLRDbf }

  TLRDbf = class(TLRDataSetControl)
  private
    function GetFilePath: string;
    function GetIndexName: string;
    function GetShowDeleted: Boolean;
    function GetTableName: string;
    procedure SetFilePath(AValue: string);
    procedure SetIndexName(AValue: string);
    procedure SetShowDeleted(AValue: Boolean);
    procedure SetTableName(AValue: string);
  protected
    procedure SetDataSource(AValue: string); override;
    procedure AfterLoad;override;
  public
    constructor Create(AOwnerPage:TfrPage); override;

    procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
    procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
  published
    property ShowDeleted: Boolean read GetShowDeleted write SetShowDeleted;
    property TableName: string read GetTableName write SetTableName;
    property IndexName: string read GetIndexName write SetIndexName;
    property FilePath: string read GetFilePath write SetFilePath;
  end;

procedure Register;

implementation
{$R lrtdbfdata_img.res}
uses LR_Utils;

var
  lrBMP_TDbf:TBitmap = nil;

procedure InitLRComp;
begin
  if not assigned(lrBMP_TDbf) then
  begin
    lrBMP_TDbf := TbitMap.Create;
    lrBMP_TDbf.LoadFromResourceName(HInstance, 'TLRDbf');
    frRegisterObject(TLRDbf, lrBMP_TDbf, 'TLRDbf', nil, otlUIControl, nil);
  end;
end;

procedure Register;
begin
  RegisterComponents('LazReport',[TlrTDbfData]);
end;

{ TLRDbf }

procedure TLRDbf.SetIndexName(AValue: string);
begin
  TDbf(DataSet).IndexName:=AValue
end;

function TLRDbf.GetFilePath: string;
begin
  Result:=TDbf(DataSet).FilePath;
end;

function TLRDbf.GetIndexName: string;
begin
  Result:=TDbf(DataSet).IndexName;
end;

function TLRDbf.GetShowDeleted: Boolean;
begin
  Result:=TDbf(DataSet).ShowDeleted;
end;

function TLRDbf.GetTableName: string;
begin
  Result:=TDbf(DataSet).TableName;
end;

procedure TLRDbf.SetFilePath(AValue: string);
begin
  TDbf(DataSet).FilePath:=AValue
end;

procedure TLRDbf.SetShowDeleted(AValue: Boolean);
begin
  TDbf(DataSet).ShowDeleted:=AValue
end;

procedure TLRDbf.SetTableName(AValue: string);
begin
  TDbf(DataSet).TableName:=AValue
end;

//TDBF not used Master-detail
procedure TLRDbf.SetDataSource(AValue: string);
begin
end;

procedure TLRDbf.AfterLoad;
begin
  try
    if FileExists(TDbf(DataSet).FilePathFull + TDbf(DataSet).TableName) then
      DataSet.Active:=FActive;
  finally
  end;
end;

constructor TLRDbf.Create(AOwnerPage: TfrPage);
begin
  inherited Create(AOwnerPage);
  BaseName := 'lrDbf';
  DataSet:=TDbf.Create(OwnerForm);
end;

procedure TLRDbf.LoadFromXML(XML: TLrXMLConfig; const Path: String);
begin
  inherited LoadFromXML(XML, Path);
  TableName  := XML.GetValue(Path+'TableName/Value'{%H-}, '');
  IndexName  := XML.GetValue(Path+'IndexName/Value'{%H-}, '');
  ShowDeleted:= XML.GetValue(Path+'ShowDeleted/Value'{%H-}, false);
  FilePath:= XML.GetValue(Path+'FilePath/Value'{%H-}, '');
end;

procedure TLRDbf.SaveToXML(XML: TLrXMLConfig; const Path: String);
begin
  inherited SaveToXML(XML, Path);
  XML.SetValue(Path+'TableName/Value'{%H-}, TableName);
  XML.SetValue(Path+'IndexName/Value'{%H-}, IndexName);
  XML.SetValue(Path+'ShowDeleted/Value'{%H-}, ShowDeleted);
  XML.SetValue(Path+'FilePath/Value'{%H-}, FilePath);
end;

initialization
  InitLRComp;

{  RegisterPropertyEditor(TypeInfo(string), TLRZQuery, 'Database', TLRZQueryDataBaseProperty);
  RegisterPropertyEditor(TypeInfo(string), TLRZConnection, 'Protocol', TLRZConnectionProtocolProperty);
}
finalization
  if Assigned(lrBMP_TDbf) then
    FreeAndNil(lrBMP_TDbf);
end.