Weaving/Tangled Rings: Help needed for CSharp Conversion (Partially Working) lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2025-09-04 07:31 Three Weaving/Tangled Rings Now how to do more rings dynamically? Also resize? ---------------------------------------------------------------------- Boleeman · 2025-09-05 15:34 Found a CSharp program that does it brilliantly. Now how to port it to Lazarus? ---------------------------------------------------------------------- gidesa · 2025-09-07 15:56 Use an online converter as this: https://www.codeconvert.ai/free-converter Maybe divide C# program in single function/procedures, and convert one by one. For example, this fragment from file Circle.cs (note that the service has a limit of 4000 characters): Code: C#  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class Circle    {        public PointF Center;        public float Radius, CircleThickness, OutlineThickness;        public Color FillColor, OutlineColor;        public List Pois = new List();        public List Angles = new List();        public int NumAssigned = 0;         public Circle(PointF center, float radius,          float circle_thickness, float outline_thickness,            Color fill_color, Color outline_color)        {            Center = center;            Radius = radius;            CircleThickness = circle_thickness;            OutlineThickness = outline_thickness;          FillColor = fill_color;            OutlineColor = outline_color;         }         // Return the circle's center.      public override string ToString()        {            return string.Format("{0}, {1}", Center.X, Center.Y);        }         // Draw the circle.        public void Draw(Graphics gr)        {          using (Pen fill_pen = new Pen(FillColor, CircleThickness))          {                using (Pen outline_pen = new Pen(OutlineColor, OutlineThickness))                {                    gr.DrawThickArc(Center, Radius, 0, 360, fill_pen, outline_pen);              }            }        } is converted to Delphi: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit CircleUnit; interface uses  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Generics.Collections, Vcl.Graphics; type  TCircle = class  private    FCenter: TPointF;    FRadius: Single;    FCircleThickness: Single;    FOutlineThickness: Single;    FFillColor: TColor;    FOutlineColor: TColor;    FPois: TList;    FAngles: TList;    FNumAssigned: Integer;  public    constructor Create(center: TPointF; radius, circle_thickness, outline_thickness: Single;       fill_color, outline_color: TColor);    destructor Destroy; override;     function ToString: string; override;    procedure Draw(gr: TCanvas);  end; implementation constructor TCircle.Create(center: TPointF; radius, circle_thickness, outline_thickness: Single;   fill_color, outline_color: TColor);begin  FCenter := center;  FRadius := radius;  FCircleThickness := circle_thickness;  FOutlineThickness := outline_thickness;  FFillColor := fill_color;  FOutlineColor := outline_color;  FPois := TList.Create;  FAngles := TList.Create;  FNumAssigned := 0;end; destructor TCircle.Destroy;begin  FPois.Free;  FAngles.Free;  inherited;end; function TCircle.ToString: string;begin  Result := Format('%f, %f', [FCenter.X, FCenter.Y]);end; procedure TCircle.Draw(gr: TCanvas);var  fill_pen: TPen;  outline_pen: TPen;begin  fill_pen := TPen.Create;  outline_pen := TPen.Create;  try    fill_pen.Color := FFillColor;    fill_pen.Width := Round(FCircleThickness);    outline_pen.Color := FOutlineColor;    outline_pen.Width := Round(FOutlineThickness);    gr.Pen := outline_pen;    gr.Brush.Color := FFillColor;    gr.Ellipse(FCenter.X - FRadius, FCenter.Y - FRadius,                FCenter.X + FRadius, FCenter.Y + FRadius);  finally    fill_pen.Free;    outline_pen.Free;  end;end; end.  Not too bad. ---------------------------------------------------------------------- Boleeman · 2025-09-10 12:38 Thanks for that idea gidesa. I gave it a go but its partially working. Some rings are missing or incomplete. The intersecting bits look correct, and the first drawn ring is always complete. The problem seems to be at: procedure TCircle.Assign(unfinished, partially_assigned: specialize TList); and at class procedure TCircle.FindPois(circles: array of TCircle); I tried replacing procedure TCircle.Assign with the CSharp conversion but it always seizes up the form (don't know why) I am going round in circles trying to get the whole conversion working correctly. Any help is greatly appreciated.  DZandaa buddy, Pal ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCircle.Assign(unfinished, partially_assigned: TList);var  first_assigned, i, index: Integer;  other: Circle;  last_was_this: Boolean;begin  if (FPois.Count = 0) or AllPoisAreAssigned then  begin    partially_assigned.Remove(Self);    Exit;  end;   first_assigned := -1;  for i := 0 to FPois.Count - 1 do  begin    if FPois[i].CircleOnTop <> nil then    begin      first_assigned := i;    Break;    end;  end;   last_was_this := (Pois[first_assigned].CircleOnTop = Self);   for i := 1 to FPois.Count - 1 do  begin    index := (first_assigned + i) mod FPois.Count;    if FPois[index].CircleOnTop = nil then    begin      other := FPois[index].OtherCircle(Self);      if last_was_this then        FPois[index].CircleOnTop := other      else        FPois[index].CircleOnTop := Self;       if not other.AllPoisAreAssigned and         (partially_assigned.IndexOf(other) = -1) then        partially_assigned.Add(other);       if unfinished.IndexOf(other) <> -1 then        unfinished.Remove(other);       Inc(NumAssigned);    end;     last_was_this := not last_was_this;  end;end; function TCircle.AllPoisAreAssigned: Boolean;begin  Result := NumAssigned = Pois.Count;end; ---------------------------------------------------------------------- Boleeman · 2025-09-11 08:15 Partially Working ---------------------------------------------------------------------- Boleeman · 2025-09-12 12:36 Got some working exactly like csharp version and others not. ---------------------------------------------------------------------- Joanna · 2025-09-13 13:43 Glad you got it working they look neat