Recent

Author Topic: From C++ Builder to Lazarus, is there any comparisson syntax, etc?  (Read 363 times)

incendio

  • Jr. Member
  • **
  • Posts: 84
Hi guys,

I came from C++ Builder environment. Is there a manual/tutorial that compare syntax, declaration, variables scope etc between C++ Builder & Lazarus ?

Thanks in advance.

440bx

  • Hero Member
  • *****
  • Posts: 826
Re: From C++ Builder to Lazarus, is there any comparisson syntax, etc?
« Reply #1 on: June 13, 2019, 06:05:38 am »
The Pascal/FPC/Delphi way is quite simple and sensible but, trying to compare it with the way things are managed in C/C++ would be, in many cases, convoluted.

I recommend you start by reading the FPC language Reference Guide.  A lot of your questions are answered there and you can mentally map the Pascal way to the C/C++ way.  You'll find that, in just about all cases (I cannot think of an exception at this time), the Pascal way is simple, powerful and flexible.  Significantly better than what most C/C++ compilers offer.

Click on the "Downloads" under "Free Pascal" (it's on the left hand side, under the Lazarus logo), that will take you to the "Downloads" page (what a surprise!) and there click on "Documentation".   The Language Reference Guide is likely the best place for you to start.

HTH.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.


PascalDragon

  • Sr. Member
  • ****
  • Posts: 352
  • Compiler Developer
Re: From C++ Builder to Lazarus, is there any comparisson syntax, etc?
« Reply #3 on: June 13, 2019, 09:07:26 am »
http://www.cs.gordon.edu/courses/cs320/handouts/C_C++_Syntax_vs_Pascal.html
A fair warning should be given here: this paper is from the last century (as can be seen by the date at the top) and compares old style Pascal with C and C++, thus not everything a modern Object Pascal compiler supports is covered there.

Peter H

  • New member
  • *
  • Posts: 22
Re: From C++ Builder to Lazarus, is there any comparisson syntax, etc?
« Reply #4 on: June 13, 2019, 09:54:01 am »
Yes,this is old, this is true.
I found this linked at Embarcadero.

Also at Embarcadero I have seen programming examples in Delphi and C++ Builder, maybe it is in the offline Delphi help system, unfortunately I dont remember where it is..

incendio

  • Jr. Member
  • **
  • Posts: 84
Re: From C++ Builder to Lazarus, is there any comparisson syntax, etc?
« Reply #5 on: June 13, 2019, 10:02:40 am »
Thank a lots guys for your info.

SymbolicFrank

  • Sr. Member
  • ****
  • Posts: 439
Re: From C++ Builder to Lazarus, is there any comparisson syntax, etc?
« Reply #6 on: June 13, 2019, 10:29:19 am »
The main differences:

- Not case sensitive.
- No header files  :D There are "interface" and "implementation" sections in your units.
- No macros/templates: use classes or class helpers.
- No multiple inheritance, use interfaces.
- Don't worry where things are stored and how you have to address them. No RAII and such. Just "Create" and "Free". And "var" for passing a pointer instead of a value. Use "try..finally" if you want to make sure the destructor fires.
- Empty brackets "()" are optional. And use "procedure" instead of "void function()").
- Don't worry about exceptions to the rules: there are very few.
- No Boost, but you probably didn't use that anyway.

And use {$mode Delphi} at the start. The classes are nearly identical.

Peter H

  • New member
  • *
  • Posts: 22
Re: From C++ Builder to Lazarus, is there any comparisson syntax, etc?
« Reply #7 on: June 13, 2019, 11:03:22 am »
The worst pitfall in my opinion is the different behaviour of for loop.

for i :=1 to func(xyz) do begin
.....
end;

func is only called once, regardless of the result.
after the loop i has an undefined value. (It has some value, but this depends on compiler version and optimization, so it is undefined.)

This is dangerous, because books often dont mention it or dont emphasize it enough.
« Last Edit: June 13, 2019, 12:08:10 pm by Peter H »