delphi中如何设置Ttable控件的filter条件

luxy 2000-08-11 09:28:00
我在编程中需要对Ttable的filter的条件根据用户的选择来设置,如根据用户输入的日期来设置filter的值,即filter的表达式中含有变量。
例如:

var
d:tdatetime;
begin
d:=strToDateTime(edit1.text)
tblContract.filter:='sdate>=d;'
end;
其中sdate为tblContract的一个field, d为变量.但上述程序出错,请问问题在那里?
我试图在d前面加:,即变量为:d,还是不行。
...全文
436 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
luxy 2000-08-11
  • 打赏
  • 举报
回复
我将程序改为:
var
d:tdatetime;
begin
d:=edit1.text;
tblContract.filter:='sdate>='+ dateToStr(d) ;
end;
问题解决了,谢谢continu兄。
luxy 2000-08-11
  • 打赏
  • 举报
回复
问题解决了,谢谢continu兄。
luxy 2000-08-11
  • 打赏
  • 举报
回复
谢谢回复!
我按feng_bd的建议试了
tblContract.filter:='sdate>=edit1.text';
运行时出错:
“Project Project1.exe raised exception class EDatabaseError with message 'TblContract:field 'edit1.text' not found”

请教continu如何将 d 格式化为你的DBMS的"时间或日期字符串",照您的程序编译出错:
[Error] Unit1.pas(73): 不相容类型: 'String'并且 'TDateTime'
continue 2000-08-11
  • 打赏
  • 举报
回复
var
d:tdatetime;
begin
d:=edit1.text;
//一定要先将 d 格式化为你的DBMS的"时间或日期字符串"
tblContract.filter:='sdate>='+ d ;
end;
feng_bd 2000-08-11
  • 打赏
  • 举报
回复
这位老弟啊,
(1)'sdate>=d;'
d是一个变量,怎么能写到字符串常量中去用呢?
(2)d:=strToDateTime(edit1.text)
Filder属性是字符串类型,你干吗要把好好的字符串edit1.text变成个DateTime呢?直接拿来用就好了!

RX Library 2.75 =============== The Set of Native Delphi Components for Borland Delphi versions 1, 2, 3, 4 & 5 and Borland C++ Builder 1, 3 & 4. 100% Source Code. Last revision date Oct 12, 1999. PLEASE FOLLOW THE INSTRUCTIONS PROVIDED IN THE INSTALLATION SECTION! TABLE OF CONTENTS ----------------- Latest Changes Overview History License Agreement Installation Demonstration Programs Source Files Using GIF Images Copyright Notes NEW FOR VERSION 2.75 -------------------- Delphi 5.0 & C++Builder 4.0 Compatibility New components: TRxLoginDialog New properties, events: TFormPlacement.RegistryRoot TFormPlacement.Version TFontComboBox.UseFonts TRxDBGrid.OnTopLeftChanged TRxDBLookupCombo.DisplayValues TStrHolder.Macros, TStrHolder.OnExpandMacros RxSpin.TValueType.vtHex New routines, methods, constants: SaveClipboardToStream, LoadClipboardFromStream (clipmon.pas) AppFileName, AppVerInfo (rxverinf.pas) XorString, XorEncode, XorDecode (strutils.pas) BUG FIXES. Overview -------- RX Library contains a large number of components, objects and routines for Borland Delphi with full source code. This library is compatible with Borland Delphi 1, 2, 3, 4, 5 and Borland C++ Builder 1, 3, 4. This collection includes over 60 native Delphi components. RX Library is a freeware product. Feel free to distribute the library as long as all files are unmodified and kept together. The authors disclaim all warranties as to this software, whether express or implied, including without limitation any implied warranties of merchantability or fitness for a particular purpose. Use under your own responsibility, but comments (even critique) in English (or in Russian) are welcome. 1. Components: TRxDBLookupCombo provides an incremental search through lookup list by directly typing into the combo control while the lookup list is displayed, LookupSource can refer to TTable, TQuery, TRxQuery or TQBEQuery. It even incrementally searches on the query results and much more... TRx
//▎============================================================▎// //▎================① 扩展的字符串操作函数 ===================▎// //▎============================================================▎// //从文件返回Ado连接字串。 function GetConnectionString(DataBaseName:string):string; //返回服务器的机器名称. function GetRemoteServerName:string; function InStr(const sShort: string; const sLong: string): Boolean; {测试通过} {* 判断s1是否包含在s2} function IntToStrEx(Value: Integer; Len: Integer; FillChar: Char = '0'): string; {测试通过} {* 扩展整数转字符串函数 Example: IntToStrEx(1,5,'0'); 返回:"00001"} function IntToStrSp(Value: Integer; SpLen: Integer = 3; Sp: Char = ','): string; {测试通过} {* 带分隔符的整数-字符转换} function ByteToBin(Value: Byte): string; {测试通过} {* 字节转二进制串} function StrRight(Str: string; Len: Integer): string; {测试通过} {* 返回字符串右边的字符 Examples: StrRight('ABCEDFG',3); 返回:'DFG' } function StrLeft(Str: string; Len: Integer): string; {测试通过} {* 返回字符串左边的字符} function Spc(Len: Integer): string; {测试通过} {* 返回空格串} function Replace(Str,s1,s2:string;CaseSensitive:Boolean):string; {测试通过} {* 返回将指定字符s1用字符串s2替换后的字符串,可支持大小写敏感由CaseSensitive操作} {example: replace('We know what we want','we','I',false) = 'I Know what I want'} function Replicate(pcChar:Char; piCount:integer):string; {在一个字符串查找某个字符串的位置} function StrNum(ShortStr:string;LongString:string):Integer; {测试通过} {* 返回某个字符串某个字符串出现的次数} function FindStr(ShortStr:String;LongStrIng:String):Integer; {测试通过} {* 返回某个字符串查找某个字符串的位置} function SubStr(psInput:String; BeginPlace,CutLeng:Integer):String; {测试通过} {* 返回从位置BeginPlace开始切取长度为CatLeng字符串} function LeftStr(psInput:String; CutLeng:Integer):String; {测试通过} {* 返回从左边第一为开始切取 CutLeng长度的字符串} function RightStr(psInput:String; CutLeng:Integer):String; {测试通过} {* 返回从右边第一为开始切取 CutLeng长度的字符串} function PadLStr(psInput:String; piWidth:Integer; pcPadWith:Char):String; {测试通过} {* 返回从psInput字符串左边开始用pcPadWith填充后总长度为PiWidth的字符串} function PadRStr(psInput:String; piWidth:Integer; pcPadWith:Char):String; {测试通过} {* 返回从psInput字符串右边开始用pcPadWith填充后总长度为PiWidth的字符串} function PadCStr(psInput:String; piWidth:Integer; pcPadWith:Char):String; {测试通过} {* 返回从psInput字符串两边开始用pcPadWith填充后总长度为PiWidth的字符串} function ChrTran(psInput:String; pcSearch:Char; pcTranWith:Char):String; {测试通过} {* 返回替换后字符串[替换单个字符] Examples: ChrTran('abCdEgdlkh','d','#'); 返回'abC#Eg#lkh'} function StrTran(psInput:String; psSearch:String; psTranWith:String):String; {测试通过} {* 返回替换后字符串[替换字符串] Examples: StrTran('aruyfbn','ruy','=====');; 返回'a=====fbn'} function Stuff(psInput:String; piBeginPlace,piCount:Integer; psStuffWith:String):String; { *返回替换后字符串[替换字符串] Examples: Stuff('ABCDEFGHI',3,4,'12345');返回'AB12345GHI'} procedure SwapStr(var s1, s2: string); {测试通过} {* 交换字串} function LinesToStr(const Lines: string): string; {测试通过} {* 多行文本转单行(换行符转'\n')} function StrToLines(const Str: string): string; {测试通过} {* 单行文本转多行('\n'转换行符)} function Encrypt(const S: String; Key: Word): String; {* 字符串加密函数} function Decrypt(const S: String; Key: Word): String; {* 字符串解密函数} function varIIF(aTest: Boolean; TrueValue, FalseValue: Variant): Variant; function varToStr(const V: Variant): string; {* VarIIF及VartoStr为变体函数} function IsDigital(Value: string): boolean; {功能说明:判断string是否全是数字} function RandomStr(aLength : Longint) : String; {随机字符串函数} //▎============================================================▎// //▎================② 扩展的日期时间操作函数 =================▎// //▎============================================================▎// function GetYear(Date: TDate): Integer; {测试通过} {* 取日期年份分量} function GetMonth(Date: TDate): Integer; {测试通过} {* 取日期月份分量} function GetDay(Date: TDate): Integer; {测试通过} {* 取日期天数分量} function GetHour(Time: TTime): Integer; {测试通过} {* 取时间小时分量} function GetMinute(Time: TTime): Integer; {测试通过} {* 取时间分钟分量} function GetSecond(Time: TTime): Integer; {测试通过} {* 取时间秒分量} function GetMSecond(Time: TTime): Integer; {测试通过} {* 取时间毫秒分量} function GetMonthLastDay(Cs_Year,Cs_Month:string):string; { *传入年、月,得到该月份最后一天} function IsLeapYear( nYear: Integer ): Boolean; {*/判断某年是否为闰年} function MaxDateTime(const Values: array of TDateTime): TDateTime; {//两个日期取较大的日期} function MinDateTime(const Values: array of TDateTime): TDateTime; {//两个日期取较小的日期} function dateBeginOfMonth(D: TDateTime): TDateTime; {//得到本月的第一天} function DateEndOfMonth(D: TDateTime): TDateTime; {//得到本月的最后一天} function DateEndOfYear(D: TDateTime): TDateTime; {//得到本年的最后一天} function DaysBetween(Date1, Date2: TDateTime): integer; {//得到两个日期相隔的天数} //▎============================================================▎// //▎===================③ 扩展的位操作函数 ====================▎// //▎============================================================▎// type TByteBit = 0..7; {* Byte类型位数范围} TWordBit = 0..15; {* Word类型位数范围} TDWordBit = 0..31; {* DWord类型位数范围} procedure SetBit(var Value: Byte; Bit: TByteBit; IsSet: Boolean); overload; {* 设置二进制位} procedure SetBit(var Value: WORD; Bit: TWordBit; IsSet: Boolean); overload; {* 设置二进制位} procedure SetBit(var Value: DWORD; Bit: TDWordBit; IsSet: Boolean); overload; {* 设置二进制位} function GetBit(Value: Byte; Bit: TByteBit): Boolean; overload; {* 取二进制位} function GetBit(Value: WORD; Bit: TWordBit): Boolean; overload; {* 取二进制位} function GetBit(Value: DWORD; Bit: TDWordBit): Boolean; overload; {* 取二进制位} //▎============================================================▎// //▎=================④扩展的文件及目录操作函数=================▎// //▎============================================================▎// function MoveFile(const sName, dName: string): Boolean; {测试通过} {* 移动文件、目录,参数为源、目标名} procedure FileProperties(const FName: string); {测试通过} {* 打开文件属性窗口} function CreatePath(path : string) : Boolean; function OpenDialog(var FileName: string; Title: string; Filter: string; Ext: string): Boolean; {* 打开文件框} function FormatPath(APath: string; Width: Integer): string; {测试通过} {* 缩短显示不下的长路径名} function GetRelativePath(Source, Dest: string): string; {测试通过} {* 取两个目录的相对路径,注意串尾不能是'\'字符!} procedure RunFile(const FName: string; Handle: THandle = 0; const Param: string = ''); {测试通过} {* 运行一个文件} function WinExecAndWait32(FileName: string; Visibility: Integer = SW_NORMAL): Integer; {测试通过} {* 运行一个文件并等待其结束} function AppPath: string; {测试通过} {* 应用程序路径} function GetDiskInfo(sFile : string; var nDiskFree,nDiskSize : Int64): boolean; {测试通过} {* 取sFile 所在磁盘空间状态 } function GetWindowsDir: string; {测试通过} {* 取Windows系统目录} function GetWinTempDir: string; {测试通过} {* 取临时文件目录} function AddDirSuffix(Dir: string): string; {测试通过} {* 目录尾加'\'修正} function MakePath(Dir: string): string; {测试通过} {* 目录尾加'\'修正} function IsFileInUse(FName: string): Boolean; {测试通过} {* 判断文件是否正在使用} function GetFileSize(FileName: string): Integer; {测试通过} {* 取文件长度} function SetFileDate(FileName: string; CreationTime, LastWriteTime, LastAccessTime: TFileTime): Boolean; {测试通过} {* 设置文件时间 Example: FileSetDate('c:\Test\Test1.exe',753160662); } function GetFileDate(FileName: string; var CreationTime, LastWriteTime, LastAccessTime: TFileTime): Boolean; {测试通过} {* 取文件时间} function FileTimeToLocalSystemTime(FTime: TFileTime): TSystemTime; {测试通过} {* 文件时间转本地时间} function LocalSystemTimeToFileTime(STime: TSystemTime): TFileTime; {测试通过} {* 本地时间转文件时间} function GetFileIcon(FileName: string; var Icon: TIcon): Boolean; {测试通过} {* 取得与文件相关的图标,成功则返回True} function CreateBakFile(FileName, Ext: string): Boolean; {测试通过} {* 创建备份文件} function Deltree(Dir: string): Boolean; {测试通过} {* 删除整个目录} function GetDirFiles(Dir: string): Integer; {测试通过} {* 取文件夹文件数} type TFindCallBack = procedure(const FileName: string; const Info: TSearchRec; var Abort: Boolean); {* 查找指定目录下文件的回调函数} procedure FindFile(const Path: string; const FileName: string = '*.*'; Proc: TFindCallBack = nil; bSub: Boolean = True; const bMsg: Boolean = True); {* 查找指定目录下文件} procedure FindFileList(Path:string;Filter,FileList:TStrings;ContainSubDir:Boolean; lb: TLabel=nil); { 功能说明:查找一个路径下的所有文件。 参数: path:路径,filter:文件扩展名过滤,FileList:文件列表, ContainSubDir:是否包含子目录} function Txtline(const txt: string): integer; {* 返回一文本文件的行数} function Html2Txt(htmlfilename: string): string; {* Html文件转化成文本文件} function OpenWith(const FileName: string): Integer; {测试通过} {* 文件打开方式} //▎============================================================▎// //▎====================⑤扩展的对话框函数======================▎// //▎============================================================▎// procedure InfoDlg(Mess: string; Caption: string = SCnInformation; Flags: Integer = MB_OK + MB_ICONINFORMATION); {测试通过} {* 显示提示窗口} function InfoOk(Mess: string; Caption: string = SCnInformation): Boolean; {测试通过} {* 显示提示确认窗口} procedure ErrorDlg(Mess: string; Caption: string = SCnError); {测试通过} {* 显示错误窗口} procedure WarningDlg(Mess: string; Caption: string = SCnWarning); {测试通过} {* 显示警告窗口} function QueryDlg(Mess: string; Caption: string = SCnInformation): Boolean; {测试通过} {* 显示查询是否窗口} procedure SetWindowAnimate(Sender : TForm; IsSetAni : bool); //▎============================================================▎// //▎=====================⑥系统功能函数=========================▎// //▎============================================================▎// procedure MoveMouseIntoControl(AWinControl: TControl); {测试通过} {* 移动鼠标到控件} function DynamicResolution(x, y: WORD): Boolean; {测试通过} {* 动态设置分辨率} procedure StayOnTop(Handle: HWND; OnTop: Boolean); {测试通过} {* 窗口最上方显示} procedure SetHidden(Hide: Boolean); {测试通过} {* 设置程序是否出现在任务栏} procedure SetTaskBarVisible(Visible: Boolean); {测试通过} {* 设置任务栏是否可见} procedure SetDesktopVisible(Visible: Boolean); {测试通过} {* 设置桌面是否可见} procedure BeginWait; {测试通过} {* 显示等待光标} procedure EndWait; {测试通过} {* 结束等待光标} function CheckWindows9598NT: string; {测试通过} {* 检测是否Win95/98/NT平台} function GetOSInfo : String; {测试通过} {* 取得当前操作平台是 Windows 95/98 还是NT} function GetCurrentUserName : string; {*获取当前Windows登录名的用户} function GetRegistryOrg_User(UserKeyType:string):string; {*获取当前注册的单位及用户名称} function GetSysVersion:string; {*//获取操作系统版本号} function WinBootMode:string; {//Windows启动模式} type PShutType = (UPowerOff, UShutdown, UReboot, ULogOff, USuspend, UHibernate); procedure WinShutDown(ShutWinType:PShutType; PForce:Boolean); {//Windows ShutDown等} //▎============================================================▎// //▎=====================⑦硬件功能函数=========================▎// //▎============================================================▎// function GetClientGUID:string; { 功能描述:在本机上得到一个GUID.去掉两端的大括号和间的横线 返回值:去掉两端的大括号和间的横线的一个GUID 适用范围:windows } function SoundCardExist: Boolean; {测试通过} {* 声卡是否存在} function GetDiskSerial(DiskChar: Char): string; {* 获取磁盘序列号} function DiskReady(Root: string) : Boolean; {*检查磁盘准备是否就绪} procedure WritePortB( wPort : Word; bValue : Byte ); {* 写串口} function ReadPortB( wPort : Word ) : Byte; {*读串口} function CPUSpeed: Double; {* 获知当前机器CPU的速率(MHz)} type TCPUID = array[1..4] of Longint; function GetCPUID : TCPUID; assembler; register; {*获取CPU的标识ID号*} function GetMemoryTotalPhys : Dword; {*获取计算机的物理内存} type TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES); function DriveState (driveletter: Char) : TDriveState; {* 检查驱动器A磁盘是否有效} //▎============================================================▎// //▎=====================⑧网络功能函数=========================▎// //▎============================================================▎// function GetComputerName:string; {* 获取网络计算机名称} function GetHostIP:string; {* 获取计算机的IP地址} function NetUserChangePassword(Domain:PWideChar; UserName:PWideChar; OldPassword:PWideChar; NewPassword:PWideChar): LongInt; stdcall; external 'netapi32.dll' name 'NetUserChangePassword'; {* // 运行平台:Windows NT/2000/XP {* // Windows 95/98/Me平台:可以用该函数修改用户的Windows登录密码} //▎============================================================▎// //▎=====================⑨汉字拼音功能函数=====================▎// //▎============================================================▎// function GetHzPy(const AHzStr: string): string; {测试通过} {* 取汉字的拼音} function HowManyChineseChar(Const s:String):Integer; {* 判断一个字符串有多少各汉字} //▎============================================================▎// //▎===================⑩数据库功能函数及过程===================▎// //▎============================================================▎// {function PackDbDbf(Var StatusMsg: String): Boolean;} {* 物理删除数据库(Db,Dbf)的数据[着了删除标记的记录]} procedure RepairDb(DbName: string); {* 修复Access表} function CreateODBCCfgInRegistry(ODBCSourceName:WideString;ServerName, DataBaseDescription:String):boolean; {* 通过注册表创建ODBC配置[创建在系统DSN页下]} function ADOConnectSysBase(Const Adocon:TadoConnection):boolean; {* 用Ado连接SysBase数据库函数} function ADOConnectLocalDB(Const Adocon:TadoConnection;Const Dbname,DbServerName:string;ValidateMode:Integer):boolean; {* 用Ado连接数据库函数} function ADOODBCConnectLocalDB(Const Adocon:TadoConnection;Const Dbname:string;ValidateMode:Integer):boolean; {* 用Ado与ODBC共同连接数据库函数} function CreatTable(LpDataBaseName,LpTableName,LpSentence:string):Boolean; {* //建立新表} function AddField(LpFieldName:string; LpDataType: TFieldType; LpSize: Word):string; {*//在表添加字段} function KillField(LpFieldName:string):String; {* //在表删除字段} function AlterTableExec(LpDataBaseName,LpSentence:string):Boolean; {* //修改表结构} function GetSQLSentence(LpTableName,LpSQLsentence:string): string; {* /修改、添加、删除表结构时的SQL句体} //▎============================================================▎// //▎======================⑾进制函数及过程======================▎// //▎============================================================▎// function StrToHex(AStr: string): string; {* 字符转化成十六进制} function HexToStr(AStr: string): string; {* 十六进制转化成字符} function TransChar(AChar: Char): Integer; //▎============================================================▎// //▎=====================⑿其它函数及过程=======================▎// //▎============================================================▎// function TrimInt(Value, Min, Max: Integer): Integer; overload; {测试通过} {* 输出限制在Min..Max之间} function IntToByte(Value: Integer): Byte; overload; {测试通过} {* 输出限制在0..255之间} function InBound(Value: Integer; Min, Max: Integer): Boolean; {测试通过} {* 判断整数Value是否在Min和Max之间} procedure CnSwap(var A, B: Byte); overload; {* 交换两个数} procedure CnSwap(var A, B: Integer); overload; {* 交换两个数} procedure CnSwap(var A, B: Single); overload; {* 交换两个数} procedure CnSwap(var A, B: Double); overload; {* 交换两个数} function RectEqu(Rect1, Rect2: TRect): Boolean; {* 比较两个Rect是否相等} procedure DeRect(Rect: TRect; var x, y, Width, Height: Integer); {* 分解一个TRect为左上角坐标x, y和宽度Width、高度Height} function EnSize(cx, cy: Integer): TSize; {* 返回一个TSize类型} function RectWidth(Rect: TRect): Integer; {* 计算TRect的宽度} function RectHeight(Rect: TRect): Integer; {* 计算TRect的高度} procedure Delay(const uDelay: DWORD); {测试通过} {* 延时} procedure BeepEx(const Freq: WORD = 1200; const Delay: WORD = 1); {Win9X下测试通过} {* 只能在Win9X下让喇叭发声} procedure ShowLastError; {测试通过} {* 显示Win32 Api运行结果信息} function writeFontStyle(FS: TFontStyles; inifile: string; write: boolean):string; {* 将字体Font.Style写入INI文件} function readFontStyle(inifile: string): TFontStyles; {* 从INI文件读取字体Font.Style文件} //function ReadCursorPos(SourceMemo: TMemo): TPoint; function ReadCursorPos(SourceMemo: TMemo): string; {* 取得TMemo 控件当前光标的行和列信息到Tpoint} function CanUndo(AMemo: TMemo): Boolean; {* 检查Tmemo控件能否Undo} procedure Undo(Amemo: Tmemo); {*实现Undo功能} procedure AutoListDisplay(ACombox:TComboBox); {* 实现ComBoBox自动下拉} function UpperMoney(small:real):string; {* 小写金额转换为大写 } function Myrandom(Num: Integer): integer; {*利用系统时间产生随机数)} procedure OpenIME(ImeName: string); {*打开输入法} procedure CloseIME; {*关闭输入法} procedure ToChinese(hWindows: THandle; bChinese: boolean); {*打开文输入法} //数据备份 procedure BackUpData(LpBackDispMessTitle:String); procedure ImageLoadGif(Picture: TPicture; filename: string); procedure ImageLoadJpg(Picture: TPicture; filename: string);
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver
一、 简单了解各控件功能   以下是各控件最简单的使用功能,其他功能依具体的实现而介绍。  TquickRep:带有坐标,作为其他报表控件(如TQRBand)的容器,它的Band属性可以自动添加各种类型的TQRBand.   TQRLabel:打印静态的文本(即不是根据数据库值来改变的),作用象Tlabel , Caption的内容就打印出来的内容。   TQRDBText:打印数据库字段值,一个值一行。作用象TDBText.把它的DataSet , DataField分别赋予Table1,Company时,将打印Table1所指向的表的Company字段的内容。   TQRSysData:打印系统信息如时间,页码,报表头等。   TQRMemo:非常象TQRLabel,只是它可以打印多行,也是打印静态数据。   TQRRichText:打印RichText格式,能够连接到一个Form上的RichEdit控件并打印它的内容,不过必须是32位版本的。   TQRShape:打印方框、圆和垂直、水平线。   TQRImage:打印静态的图片,包括(BMP,WMF,ICON).   TQRDBImage:从数据库接收图片。   TQRBand:用来确定报表的不同位置应该显示什么内容,它上面可以放控件(参见二)。   TQRGoups:Groups可以不限级别的组操作。当你连接了几个datasets到报表时可以通过Groups成组的对dataset进行操作。   二、 报表的控件摆放循序   出现在所有页上的标题(PageHeader)   标题(只有首页才有)(Title)   所有列的标题(ColumnHeader)   记录的内容,一个字段一列(Detail)   摘要(最后一页才有)(Summary)   出现在所有页上的页脚(PageFooter)   这些根据设置不同的Band(不是控件,一种类型而已,在其上面可以放其他控件)来定位。总共有六种Band。   三、 一个简单的例子   这个例子制作打印一张表的部分字段名及该字段数据内容的报表。   建立一个新project   放一个TTable到Form上,DatabaseName设为BCDEMOS,TableName指向Customer表,Active设为true.   放一个TquickRep控件在Form上,DataSet属性为Table1.(即要显示上边Table1所指向的表的内)。   展开TquickRep的Bands属性,设HasDetail为true,这时自动增加个detail band(一个TQRBand控件,故也可以直接放一个TQRBand控件,BandType属性设为detail就行了)。   放一个TQRDBText控件在detail band上面,设DataSet指向Table1,DataField指向Company。第四步是设置在报表的什么位置显示什么类型的数据,而TQRDBText则具体实现。   选TquickRep控件,按右键,选择”Preview”预览,应该看到表Customer的字段Company的所有字段值。  到这一个简单的例子就OK了,程序实现预览及利用TQRuickRep自带的打印功能只须在Form加一个按钮,它的OnClick事件为:QuickRep1->Preview();  四、一个使用TQRGoups、TQRExpr控件的报表   该报表先列出州名,接着列出该州的所有公司及公司总数,一个州列完后空一行(groups断),列出新的州名,接着列新州下的所有公司,没有填州名的公司统一列在Unknown state下面。  建立一个新project。   放一个Tquery在Tquickrep上,其SQL属性为:select * from customer order by State,Company;(即根据州、公司排序),DatabaseName为BCDMome,Active为true.   放一个TquickRep控件在Form1上,DataSet为Tquery1.   放一个TQRGroups控件在TquickRep上,这时默认为group header。(任何时候当group断或更高级别的group断,这个header都将打印出来,如果有表达式,根据表达式的值显示内容。)接着添加一个group footer band,添加时,放一个TQRBand控件在报表上,连接TQRGroups的FooterBand属性到这个QRBand,这时这个新建的TQRBand就成为Group Footer. (TQRGroup的一个重要特性是表达式,任何时候当表达式的值变时Group都将断,如表达式是按省列出城市名,当前列出广东省,当属于该省的城市列完后,表达式值改变,这时Group断,接着显示其他省的城市名。)TQRGroups的Expression属性设为Query1.State(根据不同的州来断)。   放一个TQRBand控件在报表上,BandType为rbDetail.   放一个TQRExpr控件在group header上面,其Expression属性为:if(State<>’’,State,’Unknown state’),即如果公司的州没填,就归入Unknown state,否则归入State.   放三个TQRDBText在Detail上,他们的DataSet都指向Query1,DataField分别指向Company,Contact,Phone.   在放一个TQRExpr控件在group Footer上面,Expression为’Customers in’+State+’:’+Str(Count) 作用是在每个州的公司列完后显示该州总共有多少个公司。   按右键选预览,应该看到不同的州名及其公司和公司公司总数。  五、QuickReport 条件式列印   可以直接在 TQuickReport 的 OnFilter 事件写明条件判断,OnFilter事件的引数有一个以 var 宣告的 PrintRecord 布林型态变数,将这个变数设为 True(预设值), 该笔记录便会印出;反之, 设为False,就不印出这笔记录. procedure TForm1.QuickReport1Filter(var PrintRecord: Boolean); begin PrintRecord := False; if YourTable.FieldByName(‘WantedField‘).AsInteger <= 100 then Exit; if YourTable.FieldByName(‘WantedField‘).AsInteger >= 150 then Exit; PrintRecord := True;

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧