这个代码运行会报错,Access violation at address 00404F22 in module 'Project1.exe'. Read of address 63580013.请高手告知原因???
procedure TForm1.btn1Click(Sender: TObject);
var
R: TRect;
S: string;
temp: array[0..50] of Char;
begin
R := Rect(20, 20, 150, 30);
S := 'This is a very long string which will' +
'run into multiple lines of text.';
{ 采用StrPCopy函数转化string类型为PChar类型}
DrawText(Canvas.Handle, StrPCopy(temp, S), -1, R, DT_CALCRECT or DT_WORDBREAK);
Canvas.Brush.Style := bsSolid;
Canvas.Rectangle(R);
Canvas.Brush.Style := bsClear;
DrawText(Canvas.Handle, StrPCopy(temp, S), -1, R, DT_WORDBREAK);
end;
procedure TForm1.btn1Click(Sender: TObject);
var
R: TRect;
S: string;
temp: array[0..50] of Char;
begin
R := Rect(20, 20, 150, 30);
S := 'This is a very long string which will' +
'run into multiple lines of text.';
{ 采用StrPCopy函数转化string类型为PChar类型}
DrawText(Canvas.Handle, StrPCopy(temp, S), -1, R, DT_CALCRECT or DT_WORDBREAK);
Canvas.Brush.Style := bsSolid;
Canvas.Rectangle(R);
Canvas.Brush.Style := bsClear;
DrawText(Canvas.Handle, StrPCopy(temp, S), -1, R, DT_WORDBREAK);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货