易截截图软件、单文件、免安装、纯绿色、仅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目录下),然后把 ......

Delphi 中串口通讯的实现

  Delphi 是新一代可视化开发工具,它具有功能强大、简便易用和代码执行速度快等特点,是全球公认的快速应用开发工具技术的先驱者,它越来越在构架企业信息系统方面发挥着重要作用。由于Delphi 这些显著特点,许多程序员选择Delphi作为开发工具编制各种应用程序。但是,令人惋惜的是Delphi没有自带串口 ......

怎样用DELPHI接收摄像头的图象

community.csdn.net/Expert/topic/3423/3423580.xml?temp=.7675897
主  题:  怎样用DELPHI接收摄像头的图象 
作  者:  benbenpear (笨笨) 
等  级:   
信 誉 值:  100 
所属社区:  Delphi GAME,图形处理/多媒体 
问题点数:  0  ......

C++如何调用delphi制作的dll


一、概述及示例代码
Delphi中包括许多已经封装好的类及控件,其中的非可视化控件库以功能方式划分可处理诸多应用需求。若使用C++实现系统时对某些功能简单调用delphi中现成的库时即可。因此将delphi中的库以DLL形式封装好之后如何将方法导出可供C++调用是本文记录的重点。C++调用的方式有多种,在这里只讨论一种静 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号