指针问题
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
StringArray=array of string;
PStringArray=^StringArray;
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function seqsearch(astrs:pstringarray;acount:integer;const aname:string):integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
a:array[0..4] of string=
('12345',
'23456',
'34567',
'45678',
'56789');
p:PStringArray;
implementation
{$R *.dfm}
function tform1.seqsearch(astrs:pstringarray;acount:integer;const aname:string):integer;
var
i:integer;
begin
for i:=0 to pred(acount) do
if comparetext(astrs^[i],aname)=0 then
begin
result:=i;
exit;
end;
result:=-1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
p:=@a;
edit1.Text:=inttostr(seqsearch(p,5,'34567'));
end;
end.
运行时点击按钮出错,停在了if comparetext(astrs^[i],aname)=0这句上。请问为什么,怎样解决?谢谢!