Delphi 语言以其高效、简单和强大的功能受到广大程序员的推崇。但是,直到最近推出的6.0版,由于它们都是英文版,所以用 Delphi开发数据库应用程序时,其报表预览控件在界面上显示的提示信息全都是英文字符,这对于开发中文界面的程序,显得很不协调。
笔者经过分析发现,Delphi6.0 在进行报表预览时,调用了窗体文件 Qrprev.dfm,该文件位于 \Program Files\Borland\Delphi6\Lib文件夹下。报表预览器上的工具条、按钮等控件全部在该文件中定义!找到了问题的关键所在,解决起来就比较简单了。用 Delphi6.0 打开Qrprev.dfm 文件,会发现其中定义了一个 TQRStandardPreview 对象类,在该类下,又定义了状态条(TStatusBar)、工具条(TToolBar)、预览窗体(TQRPreview)和图形列表(TImageList)四个类。我们就是要对工具条上按钮的 Caption、Hint和状态条上的Panels 的英文提示进行汉化。
文后所附程序清单标明了笔者所做的修改,其中语句前标有一个 * 号的是笔者所做的汉化修改,标有两个 * 号的是笔者为了支持中文字体和美化界面而加的语句。程序中不能加注 // 和 {} 注释语句(当然也不能保留语句前的 * 号)。如果你愿意,还可以给工具条上再定义一些按钮,甚至添加一幅图片。
当然了,应用这种方法,您还可以对 Delphi 的其它系统资源进行汉化,使您编制的软件界面更加友好,更符合中文用户的操作要求。
//Qrprev.dfm 文件的内容:
object QRStandardPreview: TQRStandardPreview
Left = 229
Top = 191
Width = 652
Height = 579
* Caption = '"西安电子科技大学电达科技公司"报表预览器'
Color = clBtnFace
** Font.Charset = GB2312_CHARSET
** Font.Height = -12
** Font.Name = '宋体'
ParentFont = True
KeyPreview = True
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnClose = FormClose
OnCreate = FormCreate
OnKeyDown = FormKeyDown
OnResize = FormResize
PixelsPerInch = 96
* TextHeight = 12
object StatusBar: TStatusBar
Left = 0
Top = 533
Width = 644
Height = 19
Panels = <
item
Alignment = taRightJustify
Text = '0%'
Width = 40
end
item
* Text = '页'
Width = 50
end>
SimplePanel = False
end
object ToolBar1: TToolBar
Left = 0
Top = 0
Width = 644
AutoSize = True
BorderWidth = 2
Flat = True
Images = Images
TabOrder = 1
** ShowCaptions = True
object ToolButton1: TToolButton
Left = 0
Top = 0
Width = 8
Caption = 'ToolButton1'
ImageIndex = 12
Style = tbsDivider
end
object ZoomFit: TToolButton
Left = 8
Top = 0
** AutoSize = True
* Hint = '缩 小'
* Caption = '缩小'
Grouped = True
ImageIndex = 0
Style = tbsCheck
OnClick = ZoomToFitClick
end
object Zoom100: TToolButton
Left = 31
Top = 0
** AutoSize = True
* Hint = '满屏100%显示'
* Caption = '满屏'
Grouped = True
ImageIndex = 1
Style = tbsCheck
OnClick = ZoomTo100Click
end
object ZoomToWidth: TToolButton
Left = 54
Top = 0
** AutoSize = True
* Hint = '适应屏幕宽度'
* Caption = '等宽'
Grouped = True
ImageIndex = 2
Style = tbsCheck
OnClick = ZoomToWidthClick
end
object Separator1: TToolButton
Left = 77
Top = 0
Width = 8
Caption = 'Separator1'
ImageIndex = 3
Style = tbsDivider
end
object FirstPage: TToolButton
Left = 85
Top = 0
** AutoSize = True
* Hint = '第一页'
* Caption = '首页'
ImageIndex = 3
OnClick = FirstPageClick
end
object PreviousPage: TToolButton
Left = 108
Top = 0
** AutoSize = True
* Hint = '上一页'
* Caption = '前页'
ImageIndex = 4
OnClick = PrevPageClick
end
object ToolButton2: TToolButton
Left = 131
Top = 0
** AutoSize = True
* Hint = '下一页'
* Caption = '后页'
ImageIndex = 5
OnClick = NextPageClick
end
object LastPage: TToolButton
Left = 154
Top = 0
** AutoSize = True
* Hint = '最后一页'
* Caption = '末页'
ImageIndex = 6
OnClick = LastPageClick
end
object Separator2: TToolButton
Left = 177
Top = 0
Width = 8
Caption = 'Separator2'
ImageIndex = 7
Style = tbsDivider
end
object PrintSetup: TToolButton
Left = 185
Top = 0
** AutoSize = True
* Hint = '打印机设置'
* Caption = '设置'
Enabled = False
ImageIndex = 7
OnClick = PrintSetupClick
end
object Print: TToolButton
Left = 208
Top = 0
** AutoSize= True
* Hint = '打印'
* Caption = '打印'
Enabled = False
ImageIndex = 8
OnClick = PrintClick
end
object Separator3: TToolButton
Left = 231
Top = 0
Width = 8
Caption = 'Separator3'
ImageIndex = 9
Style = tbsDivider
end
object SaveReport: TToolButton
Left = 239
Top = 0
** AutoSize = True
* Hint = '保存到文件'
* Caption = '保存'
ImageIndex = 10
OnClick = SaveClick
end
object LoadReport: TToolButton
Left = 262
Top = 0
** AutoSize = True
* Hint = '从文件装载'
* Caption = '装载'
ImageIndex = 9
OnClick = LoadClick
end
object Separator4: TToolButton
Left = 285
Top = 0
Width = 8
Caption = 'Separator4'
ImageIndex = 11
Style = tbsDivider
end
object ExitButton: TSpeedButton
Left = 293
Top = 0
Width = 50
Height = 22
Caption = '关闭'
OnClick = ExitClick
end
end
object QRPreview: TQRPreview
Left = 0
Top = 32
Width = 622
Height = 501
HorzScrollBar.Tracking = True
VertScrollBar.Tracking = True
Align = alClient
TabOrder = 2
OnPageAvailable = QRPreviewPageAvailable
OnProgressUpdate = QRPreviewProgressUpdate
PageNumber = 1
Zoom = 100
end
object Images: TImageList
Left = 54
Top = 42
Bitmap = {494C0101……} // 省略
end
end
张庆 zhangking@263.net QQ:9365822