📄 unit2.pas
字号:
unit Unit2;
interface
uses
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
SctVar, ExtCtrls, SctRep, SctCtrl, DB, Grids, DBGrids, sctdata, AcePage;
type
TAceGrid = class(TForm)
SctReport1: TSctReport;
ReportPage: TSctGrouppage;
ReportHeaderBand: TSctBand;
ReportHeaderBandlevel: TSctLevel;
PageHeaderBand: TSctBand;
PageHeaderBandlevel: TSctLevel;
DetailBand: TSctBand;
DetailBandlevel: TSctLevel;
PageFooterBand: TSctBand;
PageFooterBandlevel: TSctLevel;
ReportFooterBand: TSctBand;
ReportFooterBandlevel: TSctLevel;
svarDateTime: TSctDateTimeVar;
svarPage: TSctPageVar;
DataSourceGuide: TSctDataSourceGuide;
table1NAME: TSctDBVar;
table1SIZE: TSctDBVar;
table1WEIGHT: TSctDBVar;
table1AREA: TSctDBVar;
table1BMP: TSctDBVar;
procedure FormActivate(Sender: TObject);
function CreateVarLabel(Lab:TSctLabel; dbVar:TSctVar; DataField: TField): TSctLabel;
procedure CreateAceGrid(Grid: TDBGrid);
function GetDataType(f: TField): TSctDataTypes;
private
{ Private declarations }
public
{ Public declarations }
end;
var
AceGrid: TAceGrid;
implementation
uses Unit1, sctutil;
{$R *.DFM}
procedure TAceGrid.FormActivate(Sender: TObject);
begin
ReportPage.DataSource := Form1.DataSource1;
end;
procedure TAceGrid.CreateAceGrid(Grid: TDBGrid);
var i: Integer;
frm: TAceGrid;
TextLabel: TSctTextLabel;
MyVarLabel: TSctLabel;
MyVar: TSctDBVar;
MyString: String;
LeftCounter: Integer;
begin
LeftCounter := 10;
DetailBand.Stretch := True;
for i := 0 to grid.FieldCount -1 do
begin
TextLabel := TSctTextLabel.Create(self);
MyVar := TSctDbVar.Create(self);
MyVar.Name := 'SctGrid' + IntToStr(i);
MyVar.Parent := ReportPage;
MyVar.DataSource := grid.DataSource;
MyVar.DataField := grid.Fields[i].FieldName;
MyVar.UpdateLevel := DetailBandLevel;
MyVarLabel := CreateVarLabel(MyVarLabel, MyVar, grid.Fields[i]);
MyVarLabel.Parent := DetailBand;
MyVarLabel.Name := 'VarLabel' + IntToStr(i);
MyVarLabel.Left := LeftCounter;
MyVarLabel.Top := 5;
MyVarLabel.width := (8 * grid.Fields[i].DisplayWidth);
with TextLabel do
begin
Name :='TextLabel' + IntToStr(i);
Parent := PageHeaderBand;
{ Caption := grid.Fields[i].Displayname;}
Caption := grid.Fields[i].DisplayLabel;
AutoSize := True;
left := LeftCounter;
top := 0;
width := ( 8 * grid.Fields[i].DisplayWidth);
height := 25;
Font := grid.Font;
if Width > MyVarLabel.Width then
begin
Inc(LeftCounter, (Width + 5));
end
else
begin
Inc(LeftCounter, (MyVarLabel.Width + 5));
end;
end;
end;
ReportPage.DataSource := grid.DataSource;
end;
function TAceGrid.CreateVarLabel(Lab:TSctLabel; dbVar:TSctVar; DataField: TField): TSctLabel;
begin
if (GetDataType(DataField) = dtypegraphic)
or (getdatatype(DataField) = dtypeblob) then
begin
lab := tsctimagelabel.create(Reportpage.owner);
tsctimagelabel(lab).variable := dbvar;
end else if getdatatype(DataField) = dtypeboolean then
begin
lab := tsctchecklabel.create(Reportpage.owner);
tsctchecklabel(lab).variable := dbvar;
lab.bordertype := btsingle;
end else
begin
lab := tsctvarlabel.create(Reportpage.owner);
Lab.AutoSize := True;
tsctvarlabel(lab).variable := dbvar;
end;
Result := lab;
end;
function TAceGrid.GetDataType(f: TField): TSctDataTypes;
begin
case f.DataType of
ftString: result := dtypeString;
ftInteger, ftSmallInt, ftWord: result := dtypeInteger;
ftFloat,ftCurrency,ftBCD: result := dtypeFloat;
ftDateTime, ftDate, ftTime: result := dtypeDateTime;
ftBoolean: result := dtypeBoolean;
ftBlob: result := dtypeBlob;
ftMemo: result := dtypeMemo;
ftGraphic: result := dtypeGraphic;
{$ifdef WIN32}
ftFmtMemo, ftParadoxOle, ftDBaseOle, ftTypedBinary: result := dtypeBlob;
ftAutoInc: result := dtypeInteger;
{$endif}
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -