2006-12-04

将 TListBox 列表项目显示成多列

Delphi 的 TListBox 控件可显示一个列表项目集合在一个可滚动的列表中。
根据设计,一个列表框显示他的列表项目在一列中。
如果你想要在一行上显示多个项目,从而让一个列表框拥有多个列,你可以使用下面的方法:

设置 TabWidth 属性。该属性用像素值指定列宽。
当你在列表框中添加项目的时候,用“^I”分隔列,也就是大写的“i”,像下面这样:
begin
ListBox1.Items.Add('First'^I'Second'^I'Third') ;
ListBox1.Items.Add('C1R1'^I'C2R1'^I'C3R1') ;
ListBox1.Items.Add('C1R2'^I'C2R2'^I'C3R2') ;
ListBox1.Items.Add('C1R3'^I'C2R3'^I'C3R3') ;
ListBox1.Items.Add('C1R4'^I'C2R4'^I'C3R4') ;
ListBox1.Items.Add('C1R5'^I'C2R5'^I'C3R5') ;
ListBox1.Items.Add('C1R6'^I'C2R6'^I'C3R6') ;
ListBox1.Items.Add('C1R7'^I'C2R7'^I'C3R7') ;
ListBox1.Items.Add('C1R8'^I'C2R8'^I'C3R8') ;
ListBox1.Items.Add('C1R9'^I'C2R9'^I'C3R9') ;
end;


原文名称:Show TListBox Items in Multiple Columns
原文地址:http://delphi.about.com/cs/adptips2000/a/bltip1200_3.htm

2006-11-28

DevExpress QuantumGrid v6 发布!

DevExpress QuantumGrid 是一套非常优秀的 VCL 组件。近日,DevExpress 发布了DevExpress VCL QuantumGrid 的 v6 版,此版本做了许多改进,尤其是图表和搜索方面。

2006-11-25

Borland Delphi 不再,现在是 CodeGear Delphi!

TCodeGear.Create(Delphi);

官方消息:Delphi 不再是“Borland Delphi”,现在应是“CodeGear Delphi”!

有很长一段时间,About Delphi Programming 网站主页名称是“About Borland Delphi Programming”,后来改为“About Borland(DevCo) Delphi Programming”,今天(2006-11-14)他的新名字是“About CodeGear Delphi Programming”!

原文名称:Borland Delphi no more - It's CodeGear Delphi!
原文地址:http://delphi.about.com/od/humorandfun/a/codegear.htm
原文日期:2006-11-15

编程语言调查:28% 的人在使用 Delphi!

根据 CodeProject.com 上编程语言调查的当前情况,有 28% 的开发者使用 Delphi 谋生!

注:此调查目前已结束。这儿是调查结果:http://www.codeproject.com/script/survey/detail.asp?survey=613
原文写作时调查结果是 25%,调查结束时,最终的调查结果是 28%。



原文名称:Programming language poll: 25% are using Delphi!
原文地址:http://delphi.about.com/b/a/257649.htm
原文日期:2006-11-1

2006-11-01

FastReport 4 发布!

FastReport 是一款 Borland Delphi/C++ Builder/BDS 下的报表制作工具,功能强大,在国内是 Delphi 下报表开发的首选工具,当前,最新的 FastReport 4 已发布了!



以下为 FastReport 4 功能特性:

Report Designer:
- new XP-style interface
- the "Data" tab with all report datasets
- ability to draw diagrams in the "Data" tab
- code completion (Ctrl+Space)
- breakpoints
- watches
- report templates
- local guidelines (appears when you move or resize an object)
- ability to work in non-modal mode, mdi child mode

Report Preview:
- thumbnails

Print:
- split a big page to several small pages
- print several small pages on one big
- print a page on a specified sheet (with scale)
- duplex handling from print dialogue
- print copy name on each printed copy (for example, "First copy", "Second copy")

Report Core:
- "endless page" mode
- images handling, increased speed
- the "Reset page numbers" mode for groups
- reports crypting (Rijndael algorithm)
- report inheritance (both file-based and dfm-based)
- drill-down groups
- frxGlobalVariables object
- "cross-tab" object enhancements:
- improved cells appearance
- cross elements visible in the designer
- fill corner (ShowCorner property)
- side-by-side crosstabs (NextCross property)
- join cells with the same value (JoinEqualCells property)
- join the same string values in a cell (AllowDuplicates property)
- ability to put an external object inside cross-tab
- AddWidth, AddHeight properties to increase width&height of the cell
- AutoSize property, ability to resize cells manually
- line object can have arrows
- added TfrxPictureView.FileLink property (can contain variable or a file name)
- separate settings for each frame line (properties Frame.LeftLine, TopLine, RightLine, BottomLine can be set in the object inspector)
- PNG images support (uncomment {$DEFINE PNG} in the frx.inc file)
- Open Document Format for Office Applications (OASIS) exports, spreadsheet (ods) and text (odt)

Enterprise components:
- Users/Groups security support (see a demo application Demos\ClientServer\UserManager)
- Templates support
- Dynamically refresh of configuration, users/groups

官方主页:http://www.fast-report.com
试用下载:http://fast-report.com/en/download/fast-report-4-download.html

2006-10-23

7 个非常好的免费 Delphi 组件集

你是否在寻找一些免费且多功能的 Delphi 组件为你的程序添加更强的功能?不用再寻找了,下面列出了在互联网上最好的一些 Delphi 组件,他们可是免费并且包含所有源代码的。

(1)JEDI - VCL

JEDI-VCL(JVCL) 库构建于 JEDI 社区捐赠的代码。他由超过 400 个可以在你的 Delphi 和 Kylix 项目中立即重用的组件构成。整个 JEDI VCL 在 Mozilla 公共许可证(MPL)条款下分发,他可以自由使用于免费软件和共享软件,以及开放源代码工程和商业项目。

网站:http://jvcl.sourceforge.net

(2)RXLib

RxLib 是用于 Borland Delphi 和 C++ Builder 的一整套组件集,他们可以构建灵活和丰富的用户界面,最重要的一点是他们完全免费。

网站:http://sourceforge.net/projects/rxlib

(3)LMD Tools - Special Edition(特别版)

LMD Tools 的免费版,将近 100 个组件,绝对免费。

网站:http://www.lmdinnovative.com

(4)Globus VCL Extensions Library(GVCL)

一个用于 Borland Delphi 3-7 和Borland C++ Builder 5 的组件和函数库,所有单元都包含源代码。这个特定的库是一个免费软件产品,在不更改安装文件内容和单元源代码的情况下可自由分发使用这个库。

网站:
http://cpr.biblio-globus.ru/GlobusLib.htm
http://www.spellabs.ru/gvclen.htm

(5)Pro VCL Extensions Library(ProLib)

用于 Borland Delphi 和 C++ Builder 的免费组件库,包含 28 个组件和几个有用的类、过程和函数。

网站:http://barabash.org/prolib/index.html

(6)Max's Components for Delphi

15 个 Delphi 组件,全部包含源代码和帮助文件。

网站:http://www.maxcomponents.net

(7)About Delphi Programming VCL 集

超过 40 个组件,全部包含源代码。

网站:http://delphi.about.com/library/bluc/ucvcl.htm

原文名称:Top 7 Free Component Sets
原文地址:http://delphi.about.com/cs/toppicks/tp/aatpfreevclset.htm

2006-10-22

将 Delphi 组件 TWebBrowser 重设为空白页

Delphi 组件 TWebBrowser 允许在你的应用程序中显示 HTML 和一些 Web 化的文档。
在代码中导航到一个文档使用 Navigate 方法。

现在在窗体上,有一个 TWebBrowser 组件,命名为“WebBrowser1”,让其导航到 About Delphi Programming 中文版的主页你可以使用以下的代码行:
webBrowser1.Navigate('http://delphi.about.com') ;

假如,因为一些原因,你不得不清除 Web 浏览器窗口,重新设置并显示一个空白页,你需要导航到一个空白页。

以下的代码演示重设 TWebBrowser 让其显示一个空白页:
webBrowser1.Navigate('about:blank') ;

原文名称:Reset the TWebBrowser Delphi control to an Empty (Blank) Page
原文地址:http://delphi.about.com/od/adptips2006/qt/blankwebbrowser.htm

如何直接载入 HTML 到 WebBrowser

下面的代码演示如何载入一个字符串中的“静态”HTML 到一个 TWebBrowser 中:

用法:简单地拖动一个 TWebBrowser 组件的实例到窗体上,在窗体的 OnCreate 事件中载入 HTML 代码:

procedure WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ;
var
sl: TStringList;
ms: TMemoryStream;
begin
WebBrowser.Navigate('about:blank') ;
while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
Application.ProcessMessages;

if Assigned(WebBrowser.Document) then
begin
sl := TStringList.Create;
try
ms := TMemoryStream.Create;
try
sl.Text := HTMLCode;
sl.SaveToStream(ms) ;
ms.Seek(0, 0) ;
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms)) ;
finally
ms.Free;
end;
finally
sl.Free;
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject) ;
var
sHTML : string;
begin
sHTML := 'GOTO' +
'About Delphi Programming';
WBLoadHTML(WebBrowser1,sHTML) ;
end;

原文名称:How to load HTML directly to a WebBrowser
原文地址:http://delphi.about.com/cs/adptips2004/a/bltip0104_4.htm

2006-10-15

获取计算机名称和 Windows 用户名称

两个技巧:

(1)确定运行你的程序的机器在网络上的名称;
(2)获取当前使用机器的用户的名称。
function GetComputerNetName: string;
var
buffer: array[0..255] of char;
size: dword;
begin
size := 256;
if GetComputerName(buffer, size) then
Result := buffer
else
Result := ''
end;

Function GetUserFromWindows: string;
Var
UserName : string;
UserNameLen : Dword;
Begin
UserNameLen := 255;
SetLength(userName, UserNameLen) ;
If GetUserName(PChar(UserName), UserNameLen) Then
Result := Copy(UserName,1,UserNameLen - 1)
Else
Result := 'Unknown';
End;

原文名称:Get Computer Name, Get Windows User Name
原文地址:http://delphi.about.com/cs/adptips2002/a/bltip0102_3.htm

获取 EXE 文件版本信息

以下演示如何将获取一个可执行文件的版本信息,并将其放入 ListBox:
{
Usage:
VersionInformation(ListBox1)
}

{Pads or truncates a String and
Justifies Left if StrJustify=True}
Function StringPad(
InputStr,
FillChar: String;
StrLen: Integer;
StrJustify: Boolean): String;
Var
TempFill: String;
Counter : Integer;
Begin
If Not (Length(InputStr) = StrLen) Then
Begin
If Length(InputStr) > StrLen Then
Begin
InputStr := Copy(InputStr,1,StrLen) ;
End
Else
Begin
TempFill := '';
For Counter := 1 To StrLen-Length(InputStr) Do
Begin
TempFill := TempFill + FillChar;
End;
If StrJustify Then
Begin
{Left Justified}
InputStr := InputStr + TempFill;
End
Else
Begin
{Right Justified}
InputStr := TempFill + InputStr ;
End;
End;
End;
Result := InputStr;
End;


Function VersionInformation(
ListBox : TListBox): Boolean;
const
InfoNum = 11;
InfoStr : array [1..InfoNum] of String =
('CompanyName', 'FileDescription', 'FileVersion',
'InternalName', 'LegalCopyright', 'LegalTradeMarks',
'OriginalFilename', 'ProductName', 'ProductVersion',
'Comments', 'Author') ;
LabelStr : array [1..InfoNum] of String =
('Company Name', 'Description', 'File Version',
'Internal Name', 'Copyright', 'TradeMarks',
'Original File Name', 'Product Name',
'Product Version', 'Comments', 'Author') ;
var
S : String;
n, Len, j : Integer;
Buf : PChar;
Value : PChar;
begin
Try
S := Application.ExeName;
ListBox.Items.Clear;
ListBox.Sorted := True;
ListBox.Font.Name := 'Courier New';
n := GetFileVersionInfoSize(PChar(S),n) ;
If n > 0 Then Begin
Buf := AllocMem(n) ;
ListBox.Items.Add
(StringPad('Size',' ',20,True)+' = '+IntToStr(n)) ;
GetFileVersionInfo(PChar(S),0,n,Buf) ;
For j:=1 To InfoNum Do Begin
If VerQueryValue(Buf,PChar('StringFileInfo\040904E4\'+
InfoStr[j]),Pointer(Value),Len) Then
Begin
Value := PChar(Trim(Value)) ;
If Length(Value) > 0 Then
Begin
ListBox.Items.Add
(StringPad(labelStr,' ',20,True)+' = '+Value) ;
End;
End;
End;
FreeMem(Buf,n) ;
End
Else Begin
ListBox.Items.Add
('No FileVersionInfo found') ;
End;
Result := True;
Except
Result := False;
End;
End;

原文名称:Get EXE Version Information
原文地址:http://delphi.about.com/cs/adptips2001/a/bltip0701_4.htm

2006-10-10

Delphi 开源程序:TurboCash

TurboCash 是一个开源财务会计程序包。它是世界上第一个针对小型商业企业的完整功能开源财务会计程序包之一。



TurboCash 包含商业企业永远需要的大多数功能:债务人、债权人、总帐、股票管理、增值税、发票、银行对帐单、会计试算表、资产负债表和损益表,完整的报表和分析,并且兼容多企业和多用户管理。TurboCash 财务会计程序非常灵活,它可以配置成适应任何国家地区和任何小型商业企业。

下载 TurboCash
访问 TurboCash 主页

原文名称:Turbo Cash - Open Source code Delphi Application
原文地址:http://delphi.about.com/od/fullcodeprojects/ss/turbocash.htm

是否已连接到 Internet ?

下面的代码用来检查是否已连接到 Internet :
procedure TForm1.Button1Click(Sender: TObject) ;

function FuncAvail(_dllname, _funcname: string;
var _p: pointer): boolean;
{return True if _funcname exists in _dllname}
var _lib: tHandle;
begin
Result := false;
if LoadLibrary(PChar(_dllname)) = 0 then exit;
_lib := GetModuleHandle(PChar(_dllname)) ;
if _lib <> 0 then begin
_p := GetProcAddress(_lib, PChar(_funcname)) ;
if _p <> NIL then Result := true;
end;
end;

{
Call SHELL32.DLL for Win < Win98
otherwise call URL.dll
}
{button code:}
var
InetIsOffline : function(dwFlags: DWORD):
BOOL; stdcall;
begin
if FuncAvail('URL.DLL', 'InetIsOffline',
@InetIsOffline) then
if InetIsOffLine(0) = true
then ShowMessage('Not connected')
else ShowMessage('Connected!') ;
end;
原文名称:Are we connected to the Internet?
原文地址:http://delphi.about.com/cs/adptips2000/a/bltip1100_4.htm

无需安装使用 TTF 字体

以下代码演示无需在 Windows 中安装,即可在你的程序中使用 TTF(True Type)字体:
{First load it in the OnCreate event of a form):
procedure TForm1.FormCreate(Sender: TObject) ;
begin
AddFontResource('c:\FONTS\MyFont.TTF') ;
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;

{Before application terminates we must free it:}
procedure TForm1.FormClose
(Sender: TObject; var Action: TCloseAction) ;
begin
RemoveFontResource('C:\FONTS\MyFont.TTF') ;
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;
原文名称:Use TTF without Installing
原文地址:http://delphi.about.com/cs/adptips2000/a/bltip1100_3.htm

获得 Windows 版本

以下代码演示如何在代码中检查 Windows 版本:
type
TWin32Version = (wvUnknown,
wvWin95,
wvWin98,
wvWinNT,
wvWin2000) ;

function GetWinVersion: TWin32Version;
begin
Result := wvUnknown;
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
if (Win32MajorVersion > 4) or
((Win32MajorVersion = 4) and
(Win32MinorVersion > 0)) then
Result := wvWin98
else
Result := wvWin95
else
if Win32MajorVersion <= 4 then
Result := wvWinNT
else
if Win32MajorVersion = 5 then
Result := wvWin2000
end;

原文名称:Get Windows Version
原文地址:http://delphi.about.com/cs/adptips2000/a/bltip1100_2.htm

2006-10-05

如何更改 TProgressBar 的颜色

Delphi 组件 TProgressBar 显示一个进度条。进度条可对应用程序中的某一过程的处理进度提供一个可视化的反馈。

根据设计,进度条的颜色取决于 Windows。下面的代码演示如何在运行时更改 TProgressBar 的背景颜色和进度块的颜色。


uses CommCtrl, ...
...
// Set Background color
ProgressBar1.Brush.Color := clRed;
// Set Bar color
SendMessage(ProgressBar1.Handle, PBM_SETBARCOLOR, 0, clBlue) ;
原文名称:How to Change the Colors of the TProgressBar
原文地址:http://delphi.about.com/od/adptips2006/qt/colorbar.htm
源码下载:http://delphi.about.com/library/weekly/code/progressbarcolor.zip

捕获最大化和最小化菜单按钮的单击

如果你想要用户最大化或最小化一个 Delphi 窗体时有所反应,使用下面的代码:
...
public
procedure WMSysCommand
(var Msg: TWMSysCommand) ;
message WM_SYSCOMMAND;
...

implementation
...
procedure TForm1.WMSysCommand;
begin
if (Msg.CmdType = SC_MINIMIZE) or
(Msg.CmdType = SC_MAXIMIZE) then
MessageBeep(0) ;

DefaultHandler(Msg) ;
end;

原文名称:Capture Maximize/Minimize Menu button click
原文地址:http://delphi.about.com/cs/adptips1999/a/bltip0999_4.htm

隐藏标题栏

一个快速隐藏你的程序标题栏的方法:
procedure TForm1.FormCreate(Sender: TObject) ;
begin
SetWindowLong( Handle,
GWL_STYLE,
GetWindowLong( Handle, GWL_STYLE )
and not WS_CAPTION ) ;
ClientHeight := Height;
end;

原文名称:Hide Title Bar
原文地址:http://delphi.about.com/cs/adptips2000/a/bltip0100_5.htm

2006-10-03

如何使用 Delphi 组件 TXMLDocument 建立 !DocType 和 ?XML 元件

Delphi 的 TXMLDocument 组件常被用于读取并处理一个已经存在的 XML 文档,或者构建一个新的空白 XML 文档。

要给 XML 添加节点,你可以使用 AddChild 方法或者是 CreateElement 方法,他们的返回结果是 IXMLNode 接口,然后你可以利用此接口添加枝叶节点、应用属性,等等等等。

有效合法的 XML 的必要条件之一是,它提供一个"<!DOCTYPE ... >"(文档类型声明)元件和"<?xml ... >"元件。

不幸的是,Delphi TXMLDocument 组件的实现,基本上使用的是微软 XML 解析器(Microsoft XML Parser),没有提供添加“ntDocType”(TNodeType 类型)节点的方法。

这个问题的解决方案之一是,通过访问 TXMLDocument 的 XML 属性,手动添加必需的节点,XML 属性实际上是一个 TStrings 对象。

首先,使用 AddChild 方法构建你的 XML 文档。

其次,把 XML 结果赋值给一个 TStringList 对象。然后使用 TStringList 的方法(如 Insert、Add)添加附加的“元件”和“节点”到 XML 字符串。

最后,将包含在 TStringList 中的 XML 保存到一个文件。

这儿是例子:
var
sl : TStringList;
xmlDoc : TXMLDocument;
iNode : IXMLNode;
begin
xmlDoc := TXMLDocument.Create(nil) ;
try
xmlDoc.Active := true;

iNode := xmlDoc.AddChild('leaf') ;
iNode.Attributes['attrib1'] := 'value1';
iNode.Text := 'Node Text';

sl := TStringList.Create;
try
sl.Assign(xmlDoc.XML) ;

sl.Insert(0,'<!DOCTYPE ns:mys SYSTEM "myXML.dtd">') ;
sl.Insert(0,'<?xml version="1.0"?>') ;

sl.SaveToFile('c:\Test.xml') ;
finally
sl.Free;
end;

finally
xmlDoc := nil;
end;
end;
这儿是 XML 结果:
<?xml version="1.0"?>
<!DOCTYPE ns:mys SYSTEM "myXML.dtd">
<leaf attrib1="value1">Node Text</leaf>
原文名称:How to Create the !DocType and ?XML Elements using TXmlDocument Delphi component
原文地址:http://delphi.about.com/od/adptips2006/qt/doctype_txmldoc.htm
原文日期:2006-10-2

2006-10-02

启用或禁用桌面图标

以下代码演示如何启用或禁用桌面上的所有对象:
{Disable:}
EnableWindow(FindWindowEx(FindWindow('Progman', nil), HWND(0), 'ShellDll_DefView', nil), FALSE) ;

{Enable:}
EnableWindow(FindWindowEx(FindWindow('Progman', nil), HWND(0), 'ShellDll_DefView', nil), TRUE) ;
原文名称:Enable/Disable Desktop icons
原文地址:http://delphi.about.com/cs/adptips2000/a/bltip1000_5.htm

获得 RichEdit 行号

没错,TRichEdit 缺少这个功能。你可以通过使用一个 Windows 消息获得光标所在位置的行号(RichEdit 命名为 REdit):
REdit.Perform(EM_LINEFROMCHAR, REdit.SelStart, 0);
以上语句将返回行号。同样有一个 Windows 消息(EM_CHARFROMPOS)返回屏幕指标坐标所在的字符位置。查看 Windows 帮助文件可获得此方面的更多信息。注意,这些功能都十分缓慢,不应该在频繁调用的循环内部使用。

原文名称:Get the Line Number from a RichEdit
原文地址:http://delphi.about.com/cs/adptips2000/a/bltip1000_4.htm
原文日期:2006-10-1

2006-10-01

About Delphi Programming 中文版上线了!

2006年10月1日,"About Delphi Programming 中文版" 上线了!
本站主要发表 About Delphi Programming(http://delphi.about.com/)英文网站文章中译版以及 Borland Delphi 开发工具的相关资讯。

Welcome!