K
kenmen
Unregistered / Unconfirmed
GUEST, unregistred user!
请问PCHAR是啥?和DELPHI中的字符串一样吗?
我在某书上看到这个程序:
procedure TForm1.Button2Click(Sender: TObject);
var
S1: String;
begin
SetLength (S1, 100);
GetWindowText (Handle, PChar (S1), Length (S1));
S1 := S1 + ' is the title'
//this won't work
Button2.Caption := S1;
end;
这个程序是将FORM1中的CAPTION读给S1,再读给“Button2.Caption”,
但“S1 := S1 + ' is the title';”这时出错了,实现不了,要这样该:
“GetWindowText (Handle, PChar (S1), Length (S1));
S1 := String (PChar (S1));
S1 := S1 + ' is the title';”
请问为啥?
还有,不加“SetLength (S1, 100);”这句可以吗?有啥用?
我试过不加这句,结果很齐怪。
我在某书上看到这个程序:
procedure TForm1.Button2Click(Sender: TObject);
var
S1: String;
begin
SetLength (S1, 100);
GetWindowText (Handle, PChar (S1), Length (S1));
S1 := S1 + ' is the title'
//this won't work
Button2.Caption := S1;
end;
这个程序是将FORM1中的CAPTION读给S1,再读给“Button2.Caption”,
但“S1 := S1 + ' is the title';”这时出错了,实现不了,要这样该:
“GetWindowText (Handle, PChar (S1), Length (S1));
S1 := String (PChar (S1));
S1 := S1 + ' is the title';”
请问为啥?
还有,不加“SetLength (S1, 100);”这句可以吗?有啥用?
我试过不加这句,结果很齐怪。