翻譯|使用教程|編輯:楊鵬連|2021-07-23 14:05:10.603|閱讀 272 次
概述:高性能報表控件FastReport如何自定義數據庫引擎編寫,屬性編輯器。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
FastReport VCL是用于 Delphi、C++ Builder、RAD Studio 和 Lazarus 的報告和文檔創建 VCL 庫。它提供了可視化模板設計器,可以訪問 30 多種格式,并可以部署到云、網站、電子郵件和打印中。
建議將屬性編輯器代碼放在帶有 Editor 后綴的單獨文件中。在我們的例子中,有必要為TfrxIBXDatabase.DatabaseName、TfrxIBXTable.IndexName、TfrxIBXTable.TableName屬性編寫編輯器。請參閱相應章節中有關編寫屬性編輯器的更多信息。以下是此類文件的示例:
unit frxIBXEditor;
interface
{$I frx.inc}
implementation
uses
Windows, Classes, SysUtils, Forms, Dialogs, frxIBXComponents, frxCustomDB,
frxDsgnIntf, frxRes, IBDatabase, IBTable
{$IFDEF Delphi6}
, Variants
{$ENDIF};
type
TfrxDatabaseNameProperty = class(TfrxStringProperty)
public
function GetAttributes: TfrxPropertyAttributes; override;
function Edit: Boolean; override;
end;
TfrxTableNameProperty = class(TfrxStringProperty)
public
function GetAttributes: TfrxPropertyAttributes; override;
procedure GetValues; override;
end;
TfrxIndexNameProperty = class(TfrxStringProperty)
public
function GetAttributes: TfrxPropertyAttributes; override;
procedure GetValues; override;
end;
{ TfrxDatabaseNameProperty }
function TfrxDatabaseNameProperty.GetAttributes: TfrxPropertyAttributes;
begin
{ this property possesses editor }
Result := [paDialog];
end;
function TfrxDatabaseNameProperty.Edit: Boolean;
var
SaveConnected: Bool;
db: TIBDatabase;
begin
{ get link to TfrxIBXDatabase.Database }
db := TfrxIBXDatabase(Component).Database;
{ create standard OpenDialog }
with TOpenDialog.Create(nil) do
begin
InitialDir := GetCurrentDir;
{ we are interested in *.gdb files }
Filter := frxResources.Get('ftDB') + ' (*.gdb)|*.gdb|' + frxResources.Get('ftAllFiles') + ' (*.*)|*.*';
Result := Execute;
if Result then
begin
SaveConnected := db.Connected;
db.Connected := False;
{ if dialogue is completed successfully, assign new DB name }
db.DatabaseName := FileName;
db.Connected := SaveConnected;
end;
Free;
end;
end;
{ TfrxTableNameProperty }
function TfrxTableNameProperty.GetAttributes: TfrxPropertyAttributes;
begin
{ property represents list of values }
Result := [paMultiSelect, paValueList];
end;
procedure TfrxTableNameProperty.GetValues;
var
t: TIBTable;
begin
inherited;
{ get link to TIBTable component }
t := TfrxIBXTable(Component).Table;
{ fill list of tables available }
if t.Database <> nil then
t.DataBase.GetTableNames(Values, False);
end;
{ TfrxIndexProperty }
function TfrxIndexNameProperty.GetAttributes: TfrxPropertyAttributes;
begin
{ property represents list of values }
Result := [paMultiSelect, paValueList];
end;
procedure TfrxIndexNameProperty.GetValues;
var
i: Integer;
begin
inherited;
try
{ get link to TIBTable component }
with TfrxIBXTable(Component).Table do
if (TableName <> '') and (IndexDefs <> nil) then
begin
{ update indexes }
IndexDefs.Update;
{ fill list of indexes available }
for i := 0 to IndexDefs.Count - 1 do
if IndexDefs[i].Name <> '' then
Values.Add(IndexDefs[i].Name);
end;
except
end;
end;
initialization
frxPropertyEditors.Register(TypeInfo(String), TfrxIBXDataBase, 'DatabaseName', TfrxDataBaseNameProperty);
frxPropertyEditors.Register(TypeInfo(String), TfrxIBXTable, 'TableName', TfrxTableNameProperty);
frxPropertyEditors.Register(TypeInfo(String), TfrxIBXTable, 'IndexName', TfrxIndexNameProperty);
end.
如果您對 FastReport 感興趣,歡迎加入 FastReport QQ 交流群:702295239
還想要更多嗎?您可以點擊閱讀【FastReport報表2021最新資源盤點】,查找需要的教程資源。上是FastReport .NET慧正在網火熱銷售中!>>查看價格詳情
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: