Help converting Delphi code using dynamic array

I am converting some Delphi code into C++Builder XE4. I don't know the proper way to decline and resize the dynamic array " lines" which is an array of "TLines". Can you show the c++ code to declare cpp_TLine  cpp_lines; and then resize the array cpp_lines in the function cpp_Addline.

Thanks



//-----Start Delphi Code-----
  tpoint3d = record
     x,y,z: real;
  end;

  TLine = record
      p1,p2: tpoint3d; 
  end;

var
   lines: array of TLine; 


procedure Addline(ln1: TLine);
begin
     SetLength(lines,high(lines)+2);
     lines[high(lines)]:=ln1;
end;

//----End Delphi Code------


//-------Start C++ Code--------------

  typedef struct {
    double x;
    double y;
    double z;
  }cpp_ tpoint3d;

  typedef struct {
    cpp_ tpoint3d  p1;
    cpp_ tpoint3d  p2;
  }cpp_TLine


cpp_TLine  cpp_lines;  // array of cpp_TLine


void cpp_Addline( cpp_TLine  ln1 ){
     cpp_lines.Length = cpp_lines.Length+2;
     cpp_lines[cpp_lines.Length]=ln1;
}

//-------End C++ Code--------------
0
Larry
6/30/2014 7:12:10 AM
embarcadero.cppbuilder.cpp 2803 articles. 0 followers. Follow

3 Replies
580 Views

Similar Articles

[PageSpeed] 47

Hi Larry

You can use DynamicArray
ms-help://embarcadero.rs_xe5/libraries/System.DynamicArray.html#Length_of_dynamic_arrays

DynamicArray<TLine> cpp_lines;


void cpp_Addline( cpp_TLine  ln1 ){
      cpp_lines.Length =cpp_lines.High + 2; 
      cpp_lines[cpp_lines.High]:=ln1;
}     

or if you prefer STL:
# include <vector>
...
std::vector<TLine> cpp_lines;
...
void cpp_Addline( cpp_TLine  ln1 ){
      cpp_lines.push_back(In1);
}

all code not tested

Kind regards,
Rolf

> {quote:title=Larry Johnson wrote:}{quote}
> I am converting some Delphi code into C++Builder XE4. I don't know the proper way to decline and resize the dynamic array " lines" which is an array of "TLines". Can you show the c++ code to declare cpp_TLine  cpp_lines; and then resize the array cpp_lines in the function cpp_Addline.
> 
> Thanks
> 
> 
> 
> //-----Start Delphi Code-----
>   tpoint3d = record
>      x,y,z: real;
>   end;
> 
>   TLine = record
>       p1,p2: tpoint3d; 
>   end;
> 
> var
>    lines: array of TLine; 
> 
> 
> procedure Addline(ln1: TLine);
> begin
>      SetLength(lines,high(lines)+2);
>      lines[high(lines)]:=ln1;
> end;
> 
> //----End Delphi Code------
> 
> 
> //-------Start C++ Code--------------
> 
>   typedef struct {
>     double x;
>     double y;
>     double z;
>   }cpp_ tpoint3d;
> 
>   typedef struct {
>     cpp_ tpoint3d  p1;
>     cpp_ tpoint3d  p2;
>   }cpp_TLine
> 
> 
> cpp_TLine  cpp_lines;  // array of cpp_TLine
> 
> 
> void cpp_Addline( cpp_TLine  ln1 ){
>      cpp_lines.Length = cpp_lines.Length+2;
>      cpp_lines[cpp_lines.Length]=ln1;
> }
> 
> //-------End C++ Code--------------
0
Rolf
6/30/2014 10:35:43 AM
Rolf wrote:

> cpp_lines.Length =cpp_lines.High + 2;

Seems a little odd to use High+2 instead of Length+1, though the end effect 
is the same.

> cpp_lines[cpp_lines.High]:=ln1;

Don't use a colon on the assignment operator, that is Delphi syntax, not 
C/C++ syntax:

{code}
cpp_lines[cpp_lines.High] = ln1;
{code}

--
Remy Lebeau (TeamB)
0
Remy
6/30/2014 7:12:46 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Rolf wrote:
> 
> > cpp_lines.Length =cpp_lines.High + 2;
> 
> Seems a little odd to use High+2 instead of Length+1, though the end effect 
> is the same.
Yes, I agree but I just translated the Delphi code! 
> 
> > cpp_lines[cpp_lines.High]:=ln1;
> 
> Don't use a colon on the assignment operator, that is Delphi syntax, not 
> C/C++ syntax:
>
Sorry, I pasted the Delphi code and forgot to remove the colon.
 
> {code}
> cpp_lines[cpp_lines.High] = ln1;
> {code}
> 
> --
> Remy Lebeau (TeamB)
0
Rolf
6/30/2014 8:46:08 PM
Reply:

Similar Artilces:

Need Help Converting some VB Code to Delphi
I'm working with a vendor that has created a dll that I'm working with. The vendor has supplied some VB code as a sample but I'm trying to convert it so it will work in Delphi. Here is the code, I'm attempting to convert to Delphi. Can anyone help with this? Thanks, Tom MySettings.FieldList = New String() {FieldList.Settings.RunDate _ , FieldList.Settings.TradeDate _ , FieldList.Settings.TreasuryCurve _ , FieldList.Settings.AR...

help populating formview dynamically using c# code
i have tried populating the form view with the following c# code but the browser displays nothing on running the web form..   private void BindData() { FormView1.Visible = true; OledbConnection myConnection = new OledbConnection(ConnectionString); OledbDataAdapter ad = new OledbDataAdapter("SELECT * FROM projectperl", myConnection); DataSet ds = new DataSet(); ad.Fill(ds); FormView1.DataSource = ds; FormView1.DataBind(); }  help please!!   rsasp   Either you are not calling the method BindData() in your code (e.g. from Page_Load) or the table ...

converting delphi code to delphi .NET
Hi,I'm looking at converting quite a bit of old delphi code to delphi .NET .  I'm wondering can it be converted to VB.NET for certain ?  Or perhaps there are some unsupported functions etc in delphi and I should keep the code delphi ?  There are about 10,000 lines of code.   Anyone brave enough to take an estimate on how long it would take to convert 10,000 lines ?is going from delphi to delphi.NET smooth ?   Would going to another language cause complications ?Thanks! mike123   Mike123,   Sorry I can not help, however, I have the s...

Help converting a C function to Delphi (I also have working VB code include
Here is my C function: <code> LONG WINAPI EncodeWidget( IN OUT LPVOID lpParams, IN OUT DWORD* lpSize, IN DWORD dwWidgetID, IN DWORD bMix </code> I have the following VB6 code that works perfectly: <code> Private Type PARAMS dwLocations(0 To 99) As Long End Type Private Declare Function EncodeWidget Lib "xlsource.dll" (ByRef lpParams As PARAMS, _ ByRef lpSize As Long, _ ...

Convert another C++ code convert to delphi
Hello, I need the following code convert to Delphi DWORD files_count; bool error_flag = false; bool bResult; for(DWORD i=0; i < files_count && bResult && !error_flag; i++) { if(std::find(delete_file.begin(), delete_file.end(), i)==delete_file.end()) ........ here delete_file is as std::vector<int> delete_file How to convert this loop and if condition? -- Best Regards Md. Shariful Alam Khan "Md. Shariful Alam Khan" <murad_mouri@yahoo.com> wrote in message news:36441@forums.codegear.com.....

Convert C code to Delphi code? Pls!
I am writing Excel Add-In XLL in Delphi. I read documents for making XLL in VC++ from Microsoft [http://msdn.microsoft.com/en-us/library/aa730920.aspx] I am converting C code to Delphi code to make XLL in Delphi IDE. I converted it but may be errors? Somebody help me to correct it please! [CODE] //C++ typedef INT32 BOOL; /* Boolean */ typedef WCHAR XCHAR; /* Wide Character */ typedef INT32 RW; /* XL 12 Row */ typedef INT32 COL; /* XL 12 Column */ [B]//DELPHI[/B] type INT32 = Integer; BOOL= INT32; //* Boolean */ XCHAR= WideChar ; //* Wid...

superreview granted: [Bug 226597] nsObjectFrame.cpp Warning: String literal converted to char* in initialization. : [Attachment 136193] use properly sized arrays
Robert O'Callahan <roc@ocallahan.org> has granted timeless@myrealbox.com <timeless@bemail.org>'s request for superreview: Bug 226597: nsObjectFrame.cpp Warning: String literal converted to char* in initialization. http://bugzilla.mozilla.org/show_bug.cgi?id=226597 Attachment 136193: use properly sized arrays http://bugzilla.mozilla.org/attachment.cgi?id=136193&action=edit ...

superreview requested: [Bug 226597] nsObjectFrame.cpp Warning: String literal converted to char* in initialization. : [Attachment 136193] use properly sized arrays
timeless@myrealbox.com <timeless@bemail.org> has asked Robert O'Callahan <roc@ocallahan.org> for superreview: Bug 226597: nsObjectFrame.cpp Warning: String literal converted to char* in initialization. http://bugzilla.mozilla.org/show_bug.cgi?id=226597 Attachment 136193: use properly sized arrays http://bugzilla.mozilla.org/attachment.cgi?id=136193&action=edit ...

superreview granted: [Bug 235595] nsXPLookAndFeel.cpp Warning: String literal converted to char* in initialization. : [Attachment 142254] use properly sized arrays
Robert O'Callahan <roc@ocallahan.org> has granted timeless@myrealbox.com (working) <timeless@bemail.org>'s request for superreview: Bug 235595: nsXPLookAndFeel.cpp Warning: String literal converted to char* in initialization. http://bugzilla.mozilla.org/show_bug.cgi?id=235595 Attachment 142254: use properly sized arrays http://bugzilla.mozilla.org/attachment.cgi?id=142254&action=edit ...

superreview requested: [Bug 235595] nsXPLookAndFeel.cpp Warning: String literal converted to char* in initialization. : [Attachment 142254] use properly sized arrays
timeless@myrealbox.com (working) <timeless@bemail.org> has asked Robert O'Callahan <roc@ocallahan.org> for superreview: Bug 235595: nsXPLookAndFeel.cpp Warning: String literal converted to char* in initialization. http://bugzilla.mozilla.org/show_bug.cgi?id=235595 Attachment 142254: use properly sized arrays http://bugzilla.mozilla.org/attachment.cgi?id=142254&action=edit ...

Delphi 7.0 code convert to delphi XE ...
Hello All, I create an application using Web Server Application then CGI stand alone... In WebModule I add ModuleController component and IWPageProcedure... Below is my code in Delphi 7.0, this is how to call another units in webmodule... .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end; procedure TWebModule1.proLogInGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmLogIn.Create(AWebA...

[D2010] Can I use Assembly code in my Delphi code?
Hello all, I am new to Delphi, and I am just installing the trial version, but I have some question. Can I use assembly code without restrictions in my Object Pascal/Delphi code? Many thanks! Greets DelphiLynx I'm not quite certain what you mean by "without restriction", but yes you can use assembly code. I don't believe how to do so is documented though. However, you can look at VCL for some examples. Search in the VCL for ASM and you should find some. A quick google search also found this: http://delphi.about.com/library/bluc/text/uc052501a.htm none no...

problem with dynamic array of dynamic array
var a:array of array of integer; begin setlength(a,2); setlength(a[0],1); setlength(a[1],2); a[0,0]:=1; //it is ok a[0,1]:=2; //it is not ok in my understanding a[0,1]:=2 is not ok because a[0] has only one element as i declared setlength(a[0],1) so i dont understand why this code exemple is compiled and run just fine ? > {quote:title=Yossi Rozenberg wrote:}{quote} > in my understanding a[0,1]:=2 is not ok because a[0] has only one element as i declared setlength(a[0],1) so i dont understand why this code exemple is compiled and run just fine ? By default, acces...

converting delphi 2007 code to delphi XE2 -- emptyparam problem
Hi, I am trying to convert my applicantion code from delphi 2007 to delphi XE2 and i got stuck in this error "[DCC Error] ADODB_TLB.pas(4888): E2033 Types of actual and formal var parameters must be identical". This happens when we use emptyparam as an argument in a function that wants an olevariant. Example: function TAcadDatabase.CopyObjects(Objects: OleVariant): OleVariant; begin Result := DefaultInterface.CopyObjects(Objects, EmptyParam, EmptyParam); //this is where we get the ERROR end; The coyobjects function as this signature: " function CopyObjects(Object...

Web resources about - Help converting Delphi code using dynamic array - embarcadero.cppbuilder.cpp

Facebook Begins Converting Users To HTTPS
Are you willing to sacrifice a little bit of speed for a lot more safety? Facebook is asking that very question with its announcement that it ...

Facebook No Longer Converting Groups Into Pages
Back when Facebook first launched Facebook Pages, many businesses and brands who had built up substantial audiences in their Facebook Groups ...

Vert - simply converting for iPhone, iPad, and iPod touch on the iTunes App Store
Get Vert - simply converting on the App Store. See screenshots and ratings, and read customer reviews.

Converting SIM Card to Micro SIM Card - Flickr - Photo Sharing!
Place new Micro SIM into the iPhone SIM card tray

Ayaan Hirsi Ali on Converting Muslims to Christianity - YouTube
Complete video at: http://fora.tv/2010/07/29/Nomad_From_Islam_to_America_with_Ayaan_Hirsi_Ali Ayaan Hirsi Ali explains her support of missionary ...

Click go fears of converting print files
Is there a way to convert a print queue item to a .RTF or .PDF file? I like to save or email them. - The Sydney Morning Herald

Sudanese woman ordered to hang under sharia law for converting to Christianity gives birth
Khartoum, Sudan: A Christian Sudanese woman sentenced to hang for apostasy has given birth in jail, a Western diplomat said on Tuesday.

Imams warn against radicalism to Aboriginal inmates converting to Islam
The prison system has enlisted the help of ASIO to crack down on radicalisation behind bars amid revelations that Aboriginals are converting ...

Converting the world's companies one by one - The Science Show - ABC Radio National (Australian Broadcasting ...
Image: Trucks carrying logs make their way up a road in Jambi, Indonesia. A vast area of the Sumatran forest, and orangutan habitat, is being ...

Rothesay building new arena, converting existing rink to fieldhouse
The Town of Rothesay plans to build a new arena and convert the existing one into a fieldhouse.

Resources last updated: 1/22/2016 3:48:44 PM