A
awfigsk
Unregistered / Unconfirmed
GUEST, unregistred user!
TForm2 = class(TForm)
private
{ Private declarations }
lvCP:array of PChar;
cpBh:TStringList;
CheckStat:array of Boolean;
public
{ Public declarations }
constructor create(Owner:TComponent;cp:array of PChar);reintroduce;overload;
destructor destroy;override;
end;
constructor TForm2.create(Owner: TComponent
cp: array of PChar);
var
i:integer;
s:string;
begin
inherited create(Owner);
SetLength(lvCP,High(cp));
setLength(CheckStat,High(cp));
cpBh:=TStringList.Create;
for i:=Low(cp) to High(cp) do
begin
GetMem(lvCP,StrLen(cp)+1)
StrCopy(lvCP,cp);
Checkstat:=False;
[red]s:=lvCP;[/red] // 1
[red]cpBh.Add(MidStr(lvCP,1,Pos('|',lvCP)-1));[/red] //2
end;
end;
destructor TForm2.destroy;
begin
cpBh.Clear
// 3
FreeAndNil(cpbh);
inherited;
end;
上述代码有一个奇怪问题,[blue]当我将1处的代码去掉,
则3处cpbh.clear就会报错。[/blue]EInvalidPoint,
[blue]而只要加上1处的代码,就不会报错了。[/blue]
或将2处改为
cpBh.Add(MidStr(s,1,Pos('|',s)-1));,则在3处报同样的错误
并且如果我直接将1和2处的代码注释掉,而改成下面代码:
cpBh.Add(lvcp)
则程序执行到3处也不会出错。
这问题是出在哪呢?还请各位大侠指点,谢谢!
private
{ Private declarations }
lvCP:array of PChar;
cpBh:TStringList;
CheckStat:array of Boolean;
public
{ Public declarations }
constructor create(Owner:TComponent;cp:array of PChar);reintroduce;overload;
destructor destroy;override;
end;
constructor TForm2.create(Owner: TComponent
cp: array of PChar);
var
i:integer;
s:string;
begin
inherited create(Owner);
SetLength(lvCP,High(cp));
setLength(CheckStat,High(cp));
cpBh:=TStringList.Create;
for i:=Low(cp) to High(cp) do
begin
GetMem(lvCP,StrLen(cp)+1)
StrCopy(lvCP,cp);
Checkstat:=False;
[red]s:=lvCP;[/red] // 1
[red]cpBh.Add(MidStr(lvCP,1,Pos('|',lvCP)-1));[/red] //2
end;
end;
destructor TForm2.destroy;
begin
cpBh.Clear
// 3
FreeAndNil(cpbh);
inherited;
end;
上述代码有一个奇怪问题,[blue]当我将1处的代码去掉,
则3处cpbh.clear就会报错。[/blue]EInvalidPoint,
[blue]而只要加上1处的代码,就不会报错了。[/blue]
或将2处改为
cpBh.Add(MidStr(s,1,Pos('|',s)-1));,则在3处报同样的错误
并且如果我直接将1和2处的代码注释掉,而改成下面代码:
cpBh.Add(lvcp)
则程序执行到3处也不会出错。
这问题是出在哪呢?还请各位大侠指点,谢谢!