Delphi 10.3 Community PaintBox重画功能的问题

我目前正在Delphi 10.3社区版本26.0.34749.6593中编写一个小程序。没有其他组件。

我在TPaintBox上绘制的本质安装在面板中。到目前为止,一切工作正常,但是当通过“ PaintBox1.Repaint”对对象进行重新绘制时,对象得到了错误的BrushStyle(例如,当它们应该具有bsClear时,它们是bsSolid)。当然,我试图将其固定下来,但是没有运气。但是我发现,在以下几点上,某些操作无效:

    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.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;”行被调用时,什么也没有发生。我一步一步走,在这些行“ Brush.Style”仍然是“ bsSolid”之后,即使“ fig.Brush”是“ bsClear”

解释:TFigure是我自己的课。它包含有关图形的信息,例如矩形。这是父类。

我想念什么吗?我真的没有想法。谁能告诉我,为什么什么也没发生?

如果需要更多信息,请告诉我。预先谢谢你

编辑:

为了进行测试,我添加了以下行:

if Brush.Style <> fig.Brush then
   ShowMessage('Warnung!');

Brush.Style := fig.Brush;

尽管Brush.Style为bsSolid,而fig.Brush为bsClear,但实际上不会将其设置为false。

taikongman19992289 回答:Delphi 10.3 Community PaintBox重画功能的问题

您已经声明了fig : ^TFigure;,但是类实例已经是引用(指针)。因此,您正在创建一个指向引用的指针,并像使用引用一样使用该指针。

删除指针运算符并声明

fig: TFigure;

我无法验证您的代码中是否还有其他错误

本文链接:https://www.f2er.com/3115312.html

大家都在问