[Lazarus] How to make this Windows component cross-platform? Thanks.

Graeme Geldenhuys graemeg.lists at gmail.com
Wed Apr 13 16:35:30 CEST 2011


On 13/04/2011 16:23, Antônio wrote:
> I htas a problem here:
> 
> procedure TLine.SetLineWidth(const NewWidth: Integer);
> begin
>   if NewWidth <> Canvas.Pen.Width then
>   begin
>     if FArrow1 or FArrow2 then begin
> 
>        //  LineWidth:=1; // this line causes stack overflow
> 
>        Canvas.Pen.Width:=1;
>     end else Canvas.Pen.Width := NewWidth;
>     Invalidate;
>   end;
> end;

Yes, that will cause a recursive loop and end with a stack overflow.
Setting the value of LineWidth calls SetLineWidth() over and over.

Rather simple to fix. Add a new field variable FLineWidth: integer; Set
the default values in the constructor and LineWidth property declaration.

Then modify SetLineWidth() as follows:

procedure TLine.SetLineWidth(const NewWidth: Integer);
begin
  if FArrow1 or FArrow2 then
  begin
    if FLineWidth <> NewWidth then
    begin
      FLineWidth := 1;
      Canvas.Pen.Width := FLineWidth;
    end;
    Invalidate;
  end
  else
  begin
    if NewWidth <> Canvas.Pen.Width then
    begin
      FLineWidth := NewWidth;
      Canvas.Pen.Width := FLineWidth;
      Invalidate;
    end;
  end;
end;



Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/





More information about the Lazarus mailing list