//本意是提出一个字符串的第一个字符,如果为'A',返回true,否则为false
function check(strEvent:string):boolean ;
var
s:string;
s1:PChar;
begin
s1:='A';
s:=copy('strEvent',0,1);
//if pchar(s)='A' then
if strcomp(s1,Pchar(s))=0 then
Result:=true
else
Result:=false;
end;
但是check('A1')=false。
百思不得其解,求教各位大虾
function check(strEvent:string):boolean ;
var
s:string;
s1:PChar;
begin
s1:='A';
s:=copy('strEvent',0,1);
//if pchar(s)='A' then
if strcomp(s1,Pchar(s))=0 then
Result:=true
else
Result:=false;
end;
但是check('A1')=false。
百思不得其解,求教各位大虾
var
s:string;
begin
s:=copy(strEvent,0,1);
if UpperCase(s)='A' then
Result:=true
else
Result:=false;
end;
这样不行。。:-)
var
s:string;
s1:PChar;
begin
s1:='A';
s:=copy(strEvent,0,1);
//if pchar(s)='A' then
if strcomp(s1,Pchar(s))=0 then
Result:=true
else
Result:=false;
end;
to gobiz
这样不行。。:-)
===================================================================================你可以去试试!没有不可以的!你的错误在于
s:=copy('strEvent',0,1);
那么永远都是得到的'strEvent'的第一个字符s
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}function check(strEvent:string):boolean ;
var
s:string;
begin
s:=copy(strEvent,0,1);
if UpperCase(s)='A' then
Result:=true
else
Result:=false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Check(Edit1.Text) then
ShowMessage('YES')
else
ShowMessage('No');
end;end.