Android:未声明标识符

标签 android delphi delphi-xe7

这是我的代码:

procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas); 
var
  i: Integer;
begin
  Randomize;
  Paintbox1.Canvas.Brush.Color:=clWhite;
  Paintbox1.Canvas.Rectangle(0,500,500,0);
  Paintbox1.Canvas.MoveTo(1,0);
  Paintbox1.Canvas.LineTo(1,500);
  Paintbox1.Canvas.Pixels[xx,yy]:=clBlack;
  ...
end;

当我尝试编译此代码时,我得到:

identifier not declared 'Brush','Color','Rectangle','MoveTo','LineTo','TextOut','Pixels'.

最佳答案

未声明错误标识符意味着您的 PaintBox1 对象不包含属性和方法“画笔”、“颜色”、“矩形”...

在这种情况下,发生这种情况是因为 Delphi 使用新的 FireMonkey (FMX) 框架进行 Android 开发,而不是 VCL。这两个框架中的类和控件具有完全不同的根源,虽然它们确实有一些相似之处,但它们的功能、属性和方法却截然不同。最重要的是,您不能使用与 VCL 进行 Windows 开发相同的代码。

有关 FMX TCanvas 类的更多信息,您可以在以下位置找到:

http://docwiki.embarcadero.com/Libraries/XE7//en/FMX.Graphics.TCanvas_Properties http://docwiki.embarcadero.com/Libraries/XE7//en/FMX.Graphics.TCanvas_Methods

如您所见,FMX TCanvas 不再具有“画笔”属性,而是具有“填充”和“描边”画笔。

  PaintBox1.Canvas.Fill.Color := TAlphaColorRec.White;
  PaintBox1.Canvas.FillRect(RectF(0, 0, 500, 500), 0, 0, AllCorners, 1);

  PaintBox1.Canvas.Stroke.Color := TAlphaColorRec.Blue;
  PaintBox1.Canvas.Stroke.Kind := TBrushKind.Solid;
  PaintBox1.Canvas.Stroke.Thickness := 1;
  PaintBox1.Canvas.Stroke.Join := TStrokeJoin.Miter;
  PaintBox1.Canvas.DrawLine(TPointF.Create(1, 0), TPointF.Create(1, 500), 1);

关于Android:未声明标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26528795/

相关文章:

sockets - Delphi:TCP打洞

delphi - 如何使用 Omni Thread Library 的线程池控制内存使用?

delphi - 如何同步滚动 2 个不同高度的 TVirtualStringTree 控件?

arrays - 将动态数组类型分配给 TArray<T> 变量

java - SQLite Android 多选Args 一个选择参数

delphi - 通过SQL语句和adoquery在delphi中删除数据库

java - 如何检查元素是否具有特定标签? Jsoup安卓版

delphi - 为什么当 btn 为 NIL 时我可以访问 btn.Caption?

android - 如何在 onSizeChanged 中设置大小和布局?

java - 在 Android 中重现一个简单的 Foreach 循环?