Recent

Author Topic: Pascal for VisualBasic users in the Lazarus wiki  (Read 24762 times)

CM630

  • Hero Member
  • *****
  • Posts: 1340
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Pascal for VisualBasic users in the Lazarus wiki
« on: February 13, 2015, 03:08:28 pm »
I have started a Pascal for VisualBasic users page in the Lazarus wiki.
I hope it will be useful, please feel free to contribute.
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #1 on: February 13, 2015, 06:11:19 pm »
To replace the step functionality try something like:
Code: [Select]
procedure ForLoop;
var
  i, N: integer;
begin
  N := 3; //example step size
  for i:=50 downto 0 do
    If (i mod N = 0) then
    begin
       ...
    end. //for i
end. //func

where N is the step size

Leledumbo

  • Hero Member
  • *****
  • Posts: 8799
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #2 on: February 13, 2015, 07:00:50 pm »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12202
  • FPC developer.
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #3 on: February 13, 2015, 08:39:56 pm »
Cool, let's think up a language extension for every conceivable construct  >:D

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #4 on: February 14, 2015, 11:33:06 am »
marcov, you are a naughty boy! O:-)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12202
  • FPC developer.
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #5 on: February 14, 2015, 01:56:34 pm »
Btw with regard to the for loop there are many misconceptions. I can detect some of that sentiment in the VB article too.

In most languages, FOR is a shorthand for a while construct with a moving variable.

In Pascal and other Wirthian languages it was originally meant as a pure FOR, with a fixed number of iterations known before the loop starts.  (probably a reaction to the baroque loop and for proposals for Algol68)

This made optimization easier, though nowadays that is probably less important, since compilers can spend more time  (and more importantly, memory) on optimization

CM630

  • Hero Member
  • *****
  • Posts: 1340
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #6 on: February 14, 2015, 03:25:35 pm »
To replace the step functionality try something like:
...
IMHO what is important is to point out what is not doable in the manner that s.o. with experience in VB is used to. This could spend beating dead horses. There are many workarounds.
There are some other important issues like array indexing (IFAIR VB6 starts from 1, VB.NET from 0, like Pascal), string handling (functions, unicode, etc). A table with translation of the variables, hints how to enable the console, since Lazarus does not have an immediate panel (yet), etc.
For example, one of the first things a VB or Pascal user should know, starting to code in C is that myvariable is different from MYVariable.
« Last Edit: February 14, 2015, 03:34:27 pm by CM630 »
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #7 on: February 14, 2015, 08:08:53 pm »
IMHO what is important is to point out what is not doable in the manner that s.o. with experience in VB is used to.

Correct, the step feature is not supported in the for loop and this is the truth of the matter, work arounds are easy to implement and its better left for the developer to implement.

There are some other important issues like array indexing (IFAIR VB6 starts from 1, VB.NET from 0, like Pascal),

Vb6 has a define that can be used to that sets the indexing as 0 or 1 based. I prefer the pascal way where the index is defined per array and can be based on anything needed. If there was an implementation where I could simple define the element count for the array instead of the two limits that would be the most complete implementation of an array definition.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

sam707

  • Guest
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #8 on: February 14, 2015, 09:03:17 pm »
I don't know if free pascal supports it, but in earlier pascal compilerS (pascal 80)  it was possible to construct a loop inside a Set of elements. something like this:

Code: [Select]
type Tbag = set of integer;

var bag: Tbag;
     I : integer;
     ar: array[1..27] of real;

begin
  bag := (1,17,23,12..15);
  for I in bag do begin
    ar[I] := random;

  (* this loop fills ar with random numbers at indices contained in the bag *)
  (* look the 12.. 'to' ..15 inclusion ;) *)
  (* this is a 'non-linear' loop in a way because indices are unsorted *)
  end;
end;

Such loops are not a "while loops" workaround! as far as I remember I also used this construct with a modula 2 compiler (Wirthian language too)
« Last Edit: February 14, 2015, 09:10:41 pm by sam707 »

CM630

  • Hero Member
  • *****
  • Posts: 1340
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #9 on: February 14, 2015, 09:26:44 pm »
There are some other important issues like array indexing (IFAIR VB6 starts from 1, VB.NET from 0, like Pascal),

Vb6 has a define that can be used to that sets the indexing as 0 or 1 based.

I had no idea. I use VB6 only when writing Office macros.
 

 I prefer the pascal way where the index is defined per array and can be based on anything needed.
 
I am googling how to do it. Can it be done for dynamic arrays or for static only?
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #10 on: February 14, 2015, 09:55:57 pm »
Can it be done for dynamic arrays or for static only?

Only for static arrays. Dynamic arrays, being compiler-managed, have to strictly follow the constraints imposed by their behind-the-scenes management, which includes being always zero-based.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8799
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #11 on: February 15, 2015, 04:10:21 am »
I don't know if free pascal supports it...
Read my for-in loop link above

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #12 on: February 15, 2015, 09:46:11 am »
I don't know if free pascal supports it
Provided you change the code to legal Pascal syntax:
Code: [Select]
program ForInLoop;

uses sysutils;

type Tbag = set of byte;

const
  bagUpperLimit = 23;

var bag: TBag = [1,17,bagUpperLimit,12..15];
    i : byte;
    ar: array[1..bagUpperLimit] of single;

begin
  Randomize;
  for I in bag do
  begin
    ar[I]:=Random;
    WriteLn('i=',i,' ar[i]=',FloatToStr(ar[i]));
  end;
  ReadLn;
end.


sam707

  • Guest
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #13 on: February 15, 2015, 10:40:10 am »
many thanks howard for correcting my 'template', I did wrote my code on the fly with no check (I'm on holidays right now)

and YES , pascal language early broke the 'while loops" mimics and was the father/ancestor of "iterators" concept!

because in such non-linear loops, the compiler is free to 'run' the Sets without special order... So if the compiler is great, the optimizations are tuned/raised to the max!

this is another example of Pascal POWER against other languages/compilers!
« Last Edit: February 15, 2015, 10:52:58 am by sam707 »

mercury

  • Full Member
  • ***
  • Posts: 154
Re: Pascal for VisualBasic users in the Lazarus wiki
« Reply #14 on: February 15, 2015, 11:08:29 am »
I used vb6 long before, and fell strange about 'begin' and 'end'.
There no such things in vb.

 

TinyPortal © 2005-2018