飞
飞骐
Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi6中的TStrings已经实现Delimiter和DelimiterText两个新的属性,利用他们可以
很容易的实现VB中的split函数的功能.其实现也不难,你可以把这两个属性的实现代码
拷贝至Delphi5,Delphi4中,注意把平台有关的编译指示字去掉就可以了.
下面是一个完整的实例:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MyStrList : TStrings;
begin
MyStrList:=TStringList.Create;
MyStrList.Delimiter:=#32
//指定分隔符,此处为空格
MyStrList.DelimitedText:=Trim(Edit1.Text);
ListBox1.Items := MyStrList;
end;
end.
很容易的实现VB中的split函数的功能.其实现也不难,你可以把这两个属性的实现代码
拷贝至Delphi5,Delphi4中,注意把平台有关的编译指示字去掉就可以了.
下面是一个完整的实例:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MyStrList : TStrings;
begin
MyStrList:=TStringList.Create;
MyStrList.Delimiter:=#32
//指定分隔符,此处为空格
MyStrList.DelimitedText:=Trim(Edit1.Text);
ListBox1.Items := MyStrList;
end;
end.