windows - Delphi 10.3 社区 PaintBox 重绘功能的问题
问题描述
我目前正在 Delphi 10.3 Community Version 26.0.34749.6593 中制作一个小程序。没有额外的组件。
本质上,我在 TPaintBox 上绘制,它安装在面板中。到目前为止一切正常,但是当通过“PaintBox1.Repaint”重新绘制对象时,对象得到了错误的 BrushStyle(bsSolid,当它们应该有 bsClear 时)当然我试图把它固定下来,但我没有运气。但我发现在以下几点不起作用:
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
i: Integer;
fig : ^TFigure;
apen: TPenStyle;
abrush: TBrushStyle;
color1,color2: TColor;
begin
aPen := PaintBox1.Canvas.Pen.Style;
aBrush := bsStyle;
color1 := PaintBox1.Canvas.Brush.Color;
color2 := PaintBox1.Canvas.Pen.Color;
for I:=0 to List.Count-1 do
begin
fig := List.Items[i];
case fig.Typ of
f_Kreis : begin
with Paintbox1.Canvas do
begin
pen.Style := fig.Pen;
Brush.Style := fig.Brush;
pen.Color := fig.PenColor;
brush.Color := fig.BrushColor;
Ellipse(fig.X,fig.Y,fig.X2,fig.Y2);
end;
end;
f_Rechteck : begin
with PaintBox1.Canvas do
begin
Pen.Style := fig.Pen;
Brush.Style := fig.Brush;
Pen.Color := fig.PenColor;
Brush.Color := fig.BrushColor;
Rectangle(fig.X,fig.Y,fig.X2,fig.Y2);
end;
end;
f_Line : begin
with PaintBox1.Canvas do
begin
pen.Style := fig.Pen;
brush.Style := fig.Brush;
pen.Color := fig.PenColor;
brush.Color := fig.BrushColor;
MoveTo(fig.X,Fig.Y);
LineTo(fig.X2,fig.Y2);
end;
end;
end;
end;
PaintBox1.Canvas.Pen.Style := aPen;
bsStyle := aBrush;
PaintBox1.Canvas.Brush.Color := color1;
PaintBox1.Canvas.Pen.Color := color2;
end;
因此,当调用“Brush.Style := fig.Brush;”-Line 时,什么也没有发生。我一步一步走,即使“fig.Brush”是“bsClear”,这些线“Brush.Style”仍然是“bsSolid”
解释: TFigure 是我自己的课程。它包含有关绘图的信息,例如矩形。它是父类。
我想念什么吗。我真的没有想法。谁能告诉我,为什么什么都没发生?
如果您需要更多信息,请告诉我。先感谢您
编辑:
为了测试,我添加了以下行:
if Brush.Style <> fig.Brush then
ShowMessage('Warnung!');
在下面
Brush.Style := fig.Brush;
尽管 Brush.Style 是 bsSolid 而 fig.Brush 是 bsClear,但它实际上不会将其设置为 false。
解决方案
您已声明fig : ^TFigure;
,但类实例已经是引用(指针)。因此,您正在创建一个指向引用的指针,并像使用该引用一样使用该指针。
删除指针运算符并声明
fig: TFigure;
我无法验证您的代码中是否还有其他错误
推荐阅读
- elasticsearch - 设置 OIDC 身份验证时如何在 ELK 中找到“部署菜单”
- c# - Chart C# 删除数字并添加范围
- r-package - VIP 值:ropls vs metaboanalyst 软件包
- docker - 使用 docker 桌面仪表板中的运行按钮时将参数传递给图像
- python-3.7 - OpenSSL 加密错误无法借出有效证书
- google-apps-script - Google表格宏仅在E列中将“50”替换为“50+”并将“49”替换为“<50”
- reactjs - Next JS / React - 警告:不期望服务器 HTML 包含
在 - javascript - 创建菜单切换开发人员工具(如 vscode)的问题
- python - 当另一个协程发生异常时,asyncio.wait 不会停止与 websocket 调用的协程
- r - gsub 特定模式和字符串中的位置