logo hardware to software Hardware To Software

Donate with Paypal

Theory, hardware, software and code

Strange Types Circulating (in code)

Button-Add

Button Add

Memo-Add

Memo Add

Every programming language manual classically begins with data type explanation: integer, char, float, string…

We want instead to throw you directly into code, to make you feel the choral meaning; just after that we’ll introduce types.

So open Lazarus and just put two visual objects onto the Form window: we need a Button and a Memo log.

Let’s change their Name and button’s Caption properties with Object Inspector window.

Button’s Name becomes ButtonStart (Caption follows automatically), while Memo’s just Memo.

We will change Form1 Name into FormMain.

We associates a click event to ButtonStart by Object inspector or simply double clicking on it.

We’re ready!

 

 

By doing previous operations you’ll get a code similar to this one:

unit UnitMain;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  StdCtrls,TypInfo;

type

  { TFormMain }

  TFormMain = class(TForm)
    ButtonStart: TButton;
    Memo: TMemo;
    procedure ButtonStartClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 

var
  FormMain: TFormMain;

implementation

{$R *.lfm}

end.

If you compile you’ll get a perfect working application that does nothing, neither by clicking on button.
And it’s good anyway, because it works: this is a simple but often underestimated criterion when programming for the first times.

In Lazarus article we already saw the uses expression.
Just after we have type: as said we won’t cover types here. For now you must know it indicates a space where declaring a type you need.

var is for variable, used to declare every variable for a certain type.
By declaring a variable you want the compiler both to assign a unique identifier and to reserve a special space for it, making it know its type (this is important regarding physical memory occupation: generally a child occupies less space than an adult).


It’s enough for now, and we have the base which to proceed from. But… what is a unique identifier?

Pages: << 1 2 3 4 >>

Written by riccardo

November 15th, 2011 at 11:28 pm