VB vs. Delphi: What’s the Difference?

Two listings illustrate the differences between VB program and Delphi program.

Dave Jewell

January 31, 1996

1 Min Read
ITPro Today logo

This small VB program draws randomly colored lines all over the application window.

Option ExplicitSub Form_Load ()Randomize'Init random number generatorDrawWidth = 2'Set line width to 2End SubSub Timer1_Timer ()Dim R, G, B, X2, Y2'Create random RGB colorsR = 255 * RndG = 255 * RndB = 255 * Rnd'Set end point of line to random spot on formX2 = Int(DemoForm.Width * Rnd + 1)Y2 = Int(DemoForm.Height * Rnd + 1)Line -(X2, Y2), RGB(R, G, B)End Sub

This small Delphi program has almost a one-for-one correspondence to the VB program (left).

procedure TForm1.FormCreate(Sender: TObject);beginRandomize;{Init random number generator}Canvas.Pen.Width:= 2;{Set drawing width to 2}end;procedure TForm1.Timer1Timer(Sender: TObject);varR, G, B, X2, Y2: Integer;begin{Create random RGB colors}R:= Random (256);G:= Random (256);B:= Random (256);Canvas.Pen.Color:= RGB (R, G, B);{Set end point of line to random spot on form}X2:= Random (ClientWidth);Y2:= Random (ClientHeight);Canvas.LineTo (X2, Y2);end;
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like