易截截图软件、单文件、免安装、纯绿色、仅160KB

delphi TStringList的用法

TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的。
常规的用法大家都知道,现在来讨论它的一些高级的用法。
先把要讨论的几个属性列出来:
1、CommaText
2、Delimiter & DelimitedText
3、Names & Values & ValuefromIndex
先看第一个:CommaText。怎么用呢?用代码说话:
const
  constr :String = 'aaa,bbb,ccc,ddd';
var
  strs :TStrings;
  i :Integer;
begin
  strs := TStringList.Create;
  strs.CommaText := constr;
  for i := 0 to Strs.Count-1 do
    ShowMessage(Strs[i]);
end;
执行了这段代码后,可以看到ShowMessage显示出来的分别是:aaa bbb ccc ddd。
也就是说,strs.CommaText := constr这一句的作用,就是把一个字符串以','为分割符,分段添加到TStrings中。
那么如果不是以','来分割,又该怎么做呢?现在看第二个例子。使用Delimiter和DelimitedText。
const
  constr :String = 'aaa\bbb\ccc\ddd';
var
  strs :TStrings;
  i :Integer;
begin
  strs := TStringList.Create;
  strs.Delimiter := '\';
  strs.DelimitedText := constr;
  for i := 0 to Strs.Count-1 do
    ShowMessage(Strs[i]);
end;
可以看到, 显示的效果和第一个例子是一模一样的。解释一下:
Delimiter为分隔符,默认为:','。DelimitedText就是按Delimiter为分隔符的一个串,得到赋值后回把这个字符串按Delimiter的字符添加到TStrings中。
说到这里,有想起一个属性,QuoteChar。其默认值为:'"'(不包括单引号)
有何用呢?看例子:
const
  constr :String = '"aaa"\"bbb"\"ccc"\"ddd"';
var
  strs :TStrings;
  i :Integer;
begin
  strs := TStringList.Create;
  strs.Delimiter := '\';
  strs.DelimitedText := constr;
  for i := 0 to Strs.Count-1 do
    ShowMessage(Strs[i]);
end;
显示出来的仍然是aaa bbb ccc ddd。为什么不是:"aaa" "bbb" "ccc" "ddd"呢?
再来看一个例子:
const
  constr :String = '|aaa|\|bbb|\|ccc|\|ddd|';
var
  strs :TStrings;
  i :Integer;
begin
  strs := TStringList.Create;
  strs.Delimiter := '\';
  strs.


相关文档:

Delphi实现透明窗体

unit unitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2 ......

delphi 如何安装EhLib,DbGridEh控件

1、当然是先要卸载以前安装的Ehlib组件了,在菜单的“Component”的“install Packeges”里,选择ehlib XX,选择“Remove”。
2、接下来在库里加入这个控件的引用路径,先新建一个文件夹,比如“D:\Component\Ehlib”(最好把要安装的控件都拷贝到这个Component目录下),然后把 ......

asp、delphi、oracle的技术文档总结

1) Delphi向oracle中传递参数 如oracle中的参数名为erpcx 
答:如果想从表里取值到oracle,则erpcx:=trim(aq1.fieldbyname('erpcx').AsString);
否则直接用控件名字
语句为
with aperp do    
begin
connection:=dm.ADOCerp;      
parameters.Clear;&nbs ......

北京招聘:delphi程序员、软件界面设计美工


北京腾度网络科技有限公司
地址:北京海淀区学清路
电话:82755789
因工作需要,现面向北京招聘以下职位.
Delphi软件工程师
1、精通Delphi开发,熟悉VCL架构,代码风格良好。
2、有良好的团队合作精神,富有创新精神;
3、熟悉网络编程,对Indy组件,Socket开发有一定的了解;
4、熟悉面向对象编程思想,有组件或控件编 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号