AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

How convert c++ code ?

Ein Thema von sesillabubu · begonnen am 11. Dez 2010 · letzter Beitrag vom 11. Dez 2010
Antwort Antwort
sesillabubu

Registriert seit: 11. Dez 2010
2 Beiträge
 
#1

How convert c++ code ?

  Alt 11. Dez 2010, 14:25
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
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: How convert c++ code ?

  Alt 11. Dez 2010, 14:35
Hi,

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

You can use instead while do or repeat until.

Best regards
Klaus
Klaus
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#3

AW: How convert c++ code ?

  Alt 11. Dez 2010, 14:45
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;
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
sesillabubu

Registriert seit: 11. Dez 2010
2 Beiträge
 
#4

AW: How convert c++ code ?

  Alt 11. Dez 2010, 15:05
Fantastic, thanks!

Sesilla
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz