前几天在看源代码时,发现了POS和DEL函数,当时着急没有看明白它们的涵义,在使用的时候才发现理解错误了。紧接着便做了一个小测试文件,终于弄明白怎么回事了。
测试的代码:
unit test;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TPDTest = class
private
FSubStr : string;
public
constructor Create;
function PosTest : string;
end;
private
FSubStr : string;
public
constructor Create;
function PosTest : string;
end;
var
Form1: TForm1;
Form1: TForm1;
implementation
{$R *.dfm}
{ TPDTest }
constructor TPDTest.Create;
begin
FSubStr := '1001:bb,cc:dd';
end;
begin
FSubStr := '1001:bb,cc:dd';
end;
function TPDTest.PosTest: string;
var
SubStr : string;
i : Integer;
temp1,temp2,temp3,temp4 : string;
tempB : Boolean;
begin
SubStr := FSubStr;
i := Pos(',',SubStr);
tempB := i>0;
if tempB then
//for
temp1 := Trim(Copy(SubStr,1,i-1));
temp2 := Trim(Copy(SubStr,3,i-1));
temp3 := Trim(Copy(SubStr,3,i-1));
temp4 := Trim(Copy(SubStr,4,i-1));
var
SubStr : string;
i : Integer;
temp1,temp2,temp3,temp4 : string;
tempB : Boolean;
begin
SubStr := FSubStr;
i := Pos(',',SubStr);
tempB := i>0;
if tempB then
//for
temp1 := Trim(Copy(SubStr,1,i-1));
temp2 := Trim(Copy(SubStr,3,i-1));
temp3 := Trim(Copy(SubStr,3,i-1));
temp4 := Trim(Copy(SubStr,4,i-1));
Result := '测试结果是:'+IntToStr(i) +temp1+temp2+temp3+temp4;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FPDTest : TPDTest;
begin
FPDTest := TPDTest.Create;
ShowMessage(FPDTest.PosTest);
FPDTest.Free;
end;
var
FPDTest : TPDTest;
begin
FPDTest := TPDTest.Create;
ShowMessage(FPDTest.PosTest);
FPDTest.Free;
end;
end.
转载于:https://blog.51cto.com/wzcsying/69051