Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   How convert c++ code ? (https://www.delphipraxis.net/156695-how-convert-c-code.html)

sesillabubu 11. Dez 2010 14:25

How convert c++ code ?
 
Hi all,

i have a problem, it's possible to convert this c++ code into delphi. Any chance or workaround?

Delphi-Quellcode:
    list<Vector2> vList;
    const Vector2 vMin = 1.2f;
    const Vector2 vMax = 8.9f;

    list.clear();
    for (float y = vMin.y; y<=vMax.y; y+=1.0f)
    {
        for (float x = vMin.x; x<=vMax.x; x+=1.0f)
        {
       outList.push_back(Vector2(x, y));
        }
    }

Thanks in advance
Sesilla

Klaus01 11. Dez 2010 14:35

AW: How convert c++ code ?
 
Hi,

Delphi does not support floats in an for-to statement.

You can use instead while do or repeat until.

Best regards
Klaus

s.h.a.r.k 11. Dez 2010 14:45

AW: How convert c++ code ?
 
Yes, there is a way. You can use the TList (or TObjectList) instead of the c++ vector type.

Delphi-Quellcode:
type
  TVector2 = class
  private
    FX : Extended;
    FY : Extended;
  public
    constructor Create(AX, AY: Extended);
    property X : Extended read FX write FX;
    property Y : Extended read FY write FY;
  end;


var
  vList : TList;
  vMin, vMax : TVector2;
  x, y : Extended;
begin
  vList := TList.Create();

  vMin := TVector2.Create(1.2, 1.2);
  vMax := TVector2.Create(8.9, 8.9);
  try
    y := vMin.y;
    while (y < vMax.y) do
    begin
      x := vMin.x;
      while (x < vMax.x) do
      begin
        vList.Add(TVector2.Create(x, y));
        x := x + 1.0;
      end;
      y := y + 1.0;
    end;
  finally
    vMin.Free();
    vMax.Free();
  end;

  // vList contains all created vectors now...

end;

sesillabubu 11. Dez 2010 15:05

AW: How convert c++ code ?
 
Fantastic, thanks! :-D

Sesilla


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:04 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz