Skip to content

Array management by value

Form-Employers
Form Employees - by value

Suppose you have to archive some documents in a public bureau, one for every person you serve.
You fill all data, assign an identifier, and collect papers together; all is ready to be filed.
Every time you need to see these documents, the identifier shall make you find them quickly.

We know archive can be a computer file: indeed the paper scheme is well represented by bureaucratic organizer softwares, among which the most important are database managers.

Independently by the way you adopt, this matter always belongs to data's and memory's representation and management.

Talking about programming we have now a basic but enough knowledge to realize a simple manager.
What we're going to realize is a collection of records, describing hypothetical employees with just three features: name, surname and ID number.
Only records to be archived: so array is perfect.
Let's see how to deal with it and its items: in this article data will be passed by value.

Visual-elements
Visual elements

By adding, modifying and deleting employees we just want to mask the corresponding operations on array: this can help us choosing which visual elements to put onto the form.

A possible choice is shown in first picture beside; by having followed previous articles you're able to recognize buttons and memo, as well other three objects are used here: GroupBox, Edit and Label.

 

Anyway the second picture shows where you can find all them on Lazarus palette.

Let's define the record we need:

type
  pEmployee = ^TEmployee; //Define a pointer of TEmployee  //int* x in c++

  TEmployee = Record
    Id : integer;
    Name  : string;
    Surname  : string;
  end;

TEmployee is our record type, but before this we define a pointer to TEmployee: we'll use the dereference of a pointer to get access to items pointed.