Recent

Author Topic: How to define a record globally?  (Read 8071 times)

code850

  • Newbie
  • Posts: 5
How to define a record globally?
« on: October 18, 2010, 08:30:59 pm »
Hi,

I recently started learning programming. So I'm struggling now with some basic stuff. One trouble is defining a record type globally. I thought I should put it in the public declartion section of my main unit. I did it like this:

    type
        TCars: record
        name: string[30];
        price: Integer;
    end; 

and then some where to define an array:
 ShowRoom: array of TCars;

But the compiler complained and through this errror:

test.pas(61,5) Error: VAR and TYPE are allowed only in generics

So, where should I define a record so that its globally accessable to all controls I'm using in my app?

thanks in advance,

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to define a record globally?
« Reply #1 on: October 18, 2010, 08:35:20 pm »
Code: [Select]
type
  TCars = record
  name: string[30];
  price: Integer;
end;

ShowRoom = array of TCars; 

code850

  • Newbie
  • Posts: 5
Re: How to define a record globally?
« Reply #2 on: October 18, 2010, 08:56:57 pm »
Thanks for reply. I already tried your suggestion, but compiler gave same error.

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to define a record globally?
« Reply #3 on: October 18, 2010, 11:34:35 pm »
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
...
...
..

type
  TCars = record
  name: string[30];
  price: Integer;
end;
ShowRoom = array of TCars; 

type

  { TForm1 }
  TForm1 = class(TForm)
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1; 
  CarRoom: ShowRoom;
...
...
end.

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to define a record globally?
« Reply #4 on: October 18, 2010, 11:37:17 pm »
Quote
Here's my OLD turbo pascal program for your reference

USES CRT;
const maxunit=6;
type
dif_unit=record
        unitnum:string[7];
        buyer,name:string[20];
        datearrive,datesold:STRING[14];
        chasisnum:string[10];
        enginenum:string[10];
        remark:string[7];
        tcost:real;
        deduct:real;
        price:real;
        end;
unitarray=array[1..maxunit] of dif_unit;
var
   unitrec:unitarray;
   ans:char;
   xn,recnum:integer;
procedure table;
    begin
    gotoxy(1,12);writeln('ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿');
    gotoxy(1,13);writeln('³                                                                              ³');
    gotoxy(1,14);writeln('³                                                                              ³');
    gotoxy(1,15);writeln('³                                                                              ³');
    gotoxy(1,16);writeln('³                                                                              ³');
    gotoxy(1,17);writeln('³                                                                              ³');
    gotoxy(1,18);writeln('³                                                                              ³');
    gotoxy(1,19);writeln('³                                                                              ³');
    gotoxy(1,20);writeln('³                                                                              ³');
    gotoxy(1,21);writeln('³                                                                              ³');
    gotoxy(1,22);writeln('³                                                                              ³');
    gotoxy(1,23);writeln('ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ');
end;
procedure chair;
begin
    gotoxy(14,13);writeln('UNIT CODE:');
    gotoxy(12,14);writeln('DATE ARRIVE:');
    gotoxy(04,16);writeln('UNIT NAME AND MODEL:');
    gotoxy(05,17);writeln('UNIT CHASIS NUMBER:');
    gotoxy(05,18);writeln('UNIT ENGINE NUMBER:');
    gotoxy(13,20);writeln('UNIT PRICE:');
end;
procedure z;
VAR e:integer;
    begin
    for e:=1 to maxunit do
    begin
    unitrec[e].unitnum:='';
    unitrec[e].name:='';
    unitrec[e].datearrive:='';
    unitrec[e].datesold:='';
    unitrec[e].chasisnum:='';
    unitrec[e].enginenum:='';
    unitrec[e].tcost:=0;
    unitrec[e].deduct:=0;
    unitrec[e].remark:='';
    unitrec[e].price:=0;
    end;
    end;
procedure unitadd;
label u,j,k,l,h;
var
    xn,e:integer;
    xunitnum:string;
    y,t,r:BOOLEAN;
    function g:boolean;
    begin
    if unitrec[xn].unitnum='' then
    g:=true
    else
    g:=false;
    end;
    function s:boolean;
    begin
    if xunitnum = unitrec[e].unitnum then
    s:=true
    else
    s:=false;
    end;
    begin
    if (recnum=maxunit-1) then
    begin
    gotoxy(50,11);writeln('<*> UNIT FULL, NOT ACCEPTED <*>');
    gotoxy(50,11);ans:=readkey;exit;
    end;
    table;
    chair;
    gotoxy(54,4);textcolor(15+16);textbackground(0);writeln('1');normvideo;
    gotoxy(25,13);readln(xunitnum);
    if (xunitnum='') then exit;
    e:=1;
    repeat
    t:=s;
    INC(e);
    until (t=true) or (e>=maxunit);
    if t = true then
    begin
    gotoxy(58,13);textcolor(15);textbackground(0);
    writeln('RECORD ALREADY EXIST');normvideo;
    gotoxy(78,14);ans:=readkey;
    exit;
    end
    else
    begin
    xn:=1;
    repeat
    y:=g;
    inc(xn);
    until (y=true);
    IF (y=true) then
    begin
    unitrec[xn-1].unitnum:=xunitnum;
    unitrec[xn-1].remark:='UNSOLD';
    u:gotoxy(25,14);  readln(unitrec[xn-1].datearrive);
                      if (unitrec[xn-1].datearrive)='' then
                      begin unitrec[xn-1].datearrive:='';goto u;end;
    j:GOTOXY(25,16);  readln(unitrec[xn-1].name);
                      if (unitrec[xn-1].name)='' then
                      begin unitrec[xn-1].name:='';goto j;end;
    k:GOTOXY(25,17);  readln(unitrec[xn-1].chasisnum);
                      if (unitrec[xn-1].chasisnum)='' then
                      begin unitrec[xn-1].chasisnum:='';goto k;end;
    l:GOTOXY(25,18);   readln(unitrec[xn-1].enginenum);
                      if (unitrec[xn-1].enginenum)='' then
                      begin unitrec[xn-1].enginenum:='';goto l;end;
    h:r:=false;
    while not r do
    begin
    gotoxy(25,20);writeln('                                    ');
    gotoxy(25,20);
    {$i-}readln(unitrec[xn-1].price);{$I+}
    r:=(ioresult=0);
    if (not r) then begin writeln(^G);goto h;end else end;
    end;
    gotoxy(25,20);writeln(unitrec[xn-1].price:7:2);
repeat
gotoxy(60,13);writeln('ADD RECORD ! (Y/N)');
gotoxy(71,13);textcolor(15+16);textbackground(0);writeln('N');normvideo;
gotoxy(71,13);ans:=readkey;
if upcase(ans)<>'Y' then
begin
    unitrec[xn-1].unitnum:='';
    unitrec[xn-1].name:='                              ';
    unitrec[xn-1].datearrive:='                             ';
    unitrec[xn-1].chasisnum:='                              ';
    unitrec[xn-1].enginenum:='                             ';
    unitrec[xn-1].remark:='                              ';
    unitrec[xn-1].price:=0;
dec(xn);
exit;
end;
until upcase(ans)='Y';
end;
inc(recnum);
end;
procedure unitsold;
label u,m,n;
var
    e:integer;
    xunitnum:string[7];
    v,r:boolean;
    function wo:boolean;
    begin
    if xunitnum = unitrec[e].unitnum then
    wo:=true
    else
    wo:=false;
    end;

    function w:boolean;
    begin
    if xunitnum = unitrec[e].unitnum then
    if unitrec[e].remark<>'SOLD' then
    w:=true
    else
    w:=false;
    end;
    begin
    table;
    chair;
    gotoxy(54,5);textcolor(15+16);textbackground(0);writeln('2');normvideo;
    gotoxy(25,13);readln(xunitnum);
    if (xunitnum)='' then exit;
    e:=1;
    repeat
    v:=w;
    inc(e);
    until (v=true) or (e>=maxunit);
    if (v=true) then
    begin
    gotoxy(25,14);writeln(unitrec[e-1].datearrive);
    gotoxy(25,16);writeln(unitrec[e-1].name);
    gotoxy(25,17);writeln(unitrec[e-1].chasisnum);
    gotoxy(25,18);writeln(unitrec[e-1].enginenum);
    gotoxy(25,20);writeln(unitrec[e-1].price:7:2);
    gotoxy(59,22);writeln('REMARK: ',unitrec[e-1].REMARK);
    end
    else
    begin
    if v=wo then
    begin
    gotoxy(12,4);textcolor(15);textbackground(0);
    gotoxy(58,13);writeln('<-<-< UNIT SOLD >->->');normvideo;
    gotoxy(78,14);ans:=readkey;exit;
    end
    else
    begin
    gotoxy(12,4);textcolor(15);textbackground(0);
    gotoxy(55,13);writeln('>-> RECORD NOT EXIST <-<');normvideo;
    gotoxy(78,14);ans:=readkey;exit;
    end;
    end;
    repeat
    gotoxy(54,13);writeln('Considered sold ? (Y/N)');
    textcolor(15+16);textbackground(0);gotoxy(70,13);writeln('N');normvideo;
    gotoxy(70,13);ans:=readkey;
    if upcase(ans)<>'Y' then exit;
    until upcase(ans)='Y';
gotoxy(12,14);writeln('DATE ARRIVE: ',unitrec[e-1].datearrive);
gotoxy(12,15);writeln('  DATE SOLD:                                     ');
    u:gotoxy(25,15);  readln(unitrec[e-1].datesold);
                      if (unitrec[e-1].datesold)='' then
                      begin unitrec[e-1].datesold:='';
                      gotoxy(25,15);writeln('                                 ');
                      goto u;end;
gotoxy(7,19);writeln('UNIT BUYERS NAME:');
m:GOTOXY(25,19);      readln(unitrec[e-1].buyer);
                      if (unitrec[e-1].buyer)='' then
                      begin unitrec[e-1].buyer:='';
                      gotoxy(25,19);writeln('                                 ');
                      goto m;end;
gotoxy(14,21);writeln('DEDUCTION:');
n:r:=false;
while not r do
begin
gotoxy(25,21);writeln('                                    ');
gotoxy(25,21);
{$i-}readln(unitrec[e-1].deduct);{$I+}
r:=(ioresult=0);
if (not r) then begin writeln(^G);goto n;end else end;
unitrec[e-1].remark:='SOLD';
unitrec[e-1].Tcost:=unitrec[e-1].price-unitrec[e-1].deduct;
gotoxy(11,22);writeln('TOTAL PRICE:');
gotoxy(25,22);writeln(unitrec[e-1].tcost:7:2);
gotoxy(25,21);writeln('                          ');
gotoxy(25,21);writeln(unitrec[e-1].deduct:7:2);
textcolor(15+16);textbackground(0);gotoxy(70,13);writeln('Y');normvideo;
gotoxy(59,22);writeln('REMARK: ',unitrec[e-1].REMARK,'  ');
gotoxy(70,13);ans:=readkey;
end;
procedure edit;
label p,u,j,k,l,h,m,n,f,c,y,o;
var
    xn,e:integer;
    xunitnum:string[7];
    v,r:boolean;
    function s:boolean;
    begin
    if xunitnum = unitrec[e].unitnum then
    s:=true
    else
    s:=false;
    end;
    begin
    table;
    chair;
    gotoxy(54,6);textcolor(15+16);textbackground(0);writeln('3');normvideo;
    gotoxy(25,13);readln(xunitnum);
    if (xunitnum)='' then exit;
    e:=1;
    repeat
    v:=s;
    inc(e);
    until (v=true) or (e>=maxunit);
    if (v=true) then
    begin
    gotoxy(7,19);writeln('UNIT BUYERS NAME:');
    gotoxy(14,21);writeln('DEDUCTION:');
    gotoxy(8,22);writeln('TOTAL UNIT COST:');
    gotoxy(12,14);writeln('DATE ARRIVE: ');
    gotoxy(25,14);writeln(unitrec[e-1].datearrive);

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to define a record globally?
« Reply #5 on: October 18, 2010, 11:38:50 pm »
Quote
continuation

    gotoxy(56,22);writeln('REMARK: ',unitrec[e-1].remark);
    gotoxy(8,22);writeln('TOTAL UNIT COST:');
    gotoxy(25,14);writeln(unitrec[e-1].unitnum);
    gotoxy(25,16);writeln(unitrec[e-1].name);
    gotoxy(25,17);writeln(unitrec[e-1].chasisnum);
    gotoxy(25,18);writeln(unitrec[e-1].enginenum);
    gotoxy(25,19);writeln(unitrec[e-1].buyer);
    gotoxy(25,20);writeln(unitrec[e-1].price:7:2);
    gotoxy(25,21);writeln(unitrec[e-1].deduct:7:2);
    gotoxy(25,22);writeln(unitrec[e-1].tcost:7:2);
    if unitrec[e-1].remark='SOLD' then
    begin
    gotoxy(12,15);writeln('  DATE SOLD: ',unitrec[e-1].datesold);
    end;
    end
    else
    begin
    gotoxy(59,13);textcolor(15);textbackground(0);
    writeln('RECORD NOT EXIST!');normvideo;
    gotoxy(78,14);ans:=readkey;exit;
    end;
    repeat
gotoxy(56,13);writeln('DELETE RECORD ! (Y/N)');
gotoxy(70,13);textcolor(15+16);textbackground(0);writeln('N');normvideo;
gotoxy(70,13);ans:=readkey;
    if upcase(ans)<>'Y' then exit;
    until upcase(ans)='Y';
    unitrec[e-1].unitnum:='';
    unitrec[e-1].name:='';
    unitrec[e-1].chasisnum:='';
    unitrec[e-1].enginenum:='';
    unitrec[e-1].buyer:='';
    unitrec[e-1].remark:='';
    unitrec[e-1].datearrive:='';
    unitrec[e-1].datesold:='';
    unitrec[e-1].price:=0;
    unitrec[e-1].deduct:=0;
    unitrec[e-1].tcost:=0;
recnum:=recnum-1;
xn:=0;
exit;
end;
Procedure Lister;
var
    xnum,xn,e:integer;
    xunitnum:string;
    c:boolean;
    function s:boolean;
    begin
    if xunitnum = unitrec[e].unitnum then
    s:=true
    else
    s:=false;
    end;
    begin
    xnum:=recnum;
    table;
    gotoxy(54,8);textcolor(15+16);textbackground(0);writeln('5');normvideo;
    e:=1;
    repeat
    c:=s;
    inc(e);
    until (c=true) or (e>maxunit);
    if (c=true) then
    begin
    window(1,14,80,25);
    gotoxy(2,0);writeln('³   UnitNo: -> UnitName: -> Remark:');
    gotoxy(2,0);writeln('³  ---------------------------------------------------------------------------');
    for e:=1 to xnum+((maxunit-1)-recnum) do
    begin
    gotoxy(2,5);writeln('          ',unitrec[e].unitnum,'     ->      ',unitrec[e].name,'      ->      ',
    unitrec[e].remark);
    ans:=readkey;
    gotoxy(2,5);writeln('                                                                              ');
    end;
    end
    else
begin
    gotoxy(54,13);writeln('<*> NO RECORD EXIST <*>');
    gotoxy(54,08);ans:=readkey;exit;
end;
window(1,1,80,25);
end;
procedure programmers;
begin
gotoxy(30,17);writeln('Programmed by:');
gotoxy(30,18);writeln('              Rocamora Roderick');
gotoxy(30,19);writeln('              Samonte Arlene');
gotoxy(30,20);writeln('              Butaslac Teofredo');
gotoxy(30,21);writeln('              Salenga Eva Alice');
gotoxy(30,22);writeln('Submitted to :');
gotoxy(30,23);writeln('              Engr. Noel Khu Amao');
end;
procedure status;
begin
programmers;
gotoxy(15,2);writeln('Limited Edition');
gotoxy(5,3);writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
gotoxy(5,4);writeln('º                                 º');
gotoxy(5,5);writeln('º  Maximum unit to input     : ',maxunit-1 ,'  º');
gotoxy(5,6);writeln('º  Number of Record inputed  : ',recnum,'  º');
gotoxy(5,7);writeln('º  Remaining records to input: ',(maxunit-1) - recnum,'  º');
gotoxy(5,8);writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
gotoxy(15,4);textcolor(15);textbackground(0);writeln('Record Analyzer');
gotoxy(43,17);writeln(':');gotoxy(43,22);writeln(':');normvideo;
gotoxy(22,4);textcolor(15+16);textbackground(0);writeln('A');normvideo;
end;
    procedure exitout;
    begin
    textcolor(15+16);textbackground(0);
    gotoxy(55,12);writeln('THANK YOU ENCODE AGAIN');
    normvideo;
    end;
    begin
    z;
    recnum:=0;
    xn:=0;
    repeat
    clrscr;
    status;
    gotoxy(50,1); writeln('ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿');
    gotoxy(50,2); writeln('³');
    textcolor(15);textbackground(0);
    gotoxy(53,2); writeln('NISSAN CARS INCORPORATED');
    normvideo;
    gotoxy(80,2); writeln('³');
    gotoxy(50,3); writeln('³            MENU             ³');
    gotoxy(50,4); writeln('³  (1) NEW ARRIVAL UNIT       ³');
    gotoxy(50,5); writeln('³  (2) UNIT SOLD (PULL-OUT)   ³');
    gotoxy(50,6); writeln('³  (3) QUERY/EDIT UNIT        ³');
    gotoxy(50,7); writeln('³  (4) QUERY/DELETE UNIT      ³');
    gotoxy(50,08);writeln('³  (5) LIST RECORD REMARK     ³');
    gotoxy(50,09);writeln('³  (6) QUIT                   ³');
    gotoxy(50,10);writeln('ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ');
    gotoxy(50,11);writeln('>>>SELECT A NUMBER (1.( ).6)<<<');
    gotoxy(73,11);ans:=readkey;
    case ans of
    '1':unitadd;
    '2':unitsold;
    '3':edit;
    '4':delete;
    '5':Lister;
    '6':;
    else
    gotoxy(55,15);writeln('>>> ERROR SELECTION <<<');
    ans:=readkey;
    end;
    until (ans='6');
    exitout;
    ans:=readkey;
    exit;
    end.

    SAMPLE PROGRAM <:Statement Application:>

                           PROGRAM LABEL/GOTO AND IF THEN...ELSE STATEMENT;
EXPLAINATIONS:
{ The program continues to operate until ( i is greaterthan equal to five )
  program usage: inc(i) - means increase i, if i=0 then increase i=1 to up}
                           label a;
                           var i:integer;
                           begin
                           i:=0;
                           a:
                           write('Welcome to my ( H N B ) program');
                           readln;
                           inc(i);
                           if i <=5 then
                           goto a
                           else if i>5 then
                           end.

                           PROGRAM REPEAT_UNTIL STATEMENT;
EXPLAINATIONS:
{ the program continues to ask until you press 'y' or 'Y'
  program usage: upcase(a)='Y'  - pressing small letter or capital letter
                 readln(a)      - use for inputing any kind of variable(Var)}
                           var a:char;
                           begin
                           repeat
                           write('Are you Welcome to my program? ( Y/N )');
                           readln(a);
                           until upcase(a)='Y';
                           end.

                           PROGRAM WHILEDO STATEMENT;
EXPLAINATIONS:
{ the program statement will not accept letters
  program usage: B is boolean( it can be true if the statement is true or
                                         false if the statement is not true.
  $i-           - input structure
  $i+           - output structure
B:=(ioresult=0) - output in B is now true because of (i)nput(o)output
                  is equal to Zero.                                  }
                           var B:boolean; { true or false }
                               numberonly:integer;
                           begin
                           B:false;
                           while not b do   { while not false says }
                           begin
                           {$i-} readln(numberonly); {$i+}
                           b:=(ioresult=0);
                           if not b then     { if not number typed then }
                           write('the number you dial is not on service')
                           else
                           write('its good to follow instruction');
                           readln;
                           end;

                           PROGRAM CASE...ELSE STATEMENT;
EXPLAINATIONS:
{ The statement of the program is to select only ( 1 or 2 )
  program usage : uses crt - uses the Cathod Ray Tube (in TV picture tube)
              ans:=readkey - waiting for any key to press without enter key
      not like readln(ans) - is dependent in keystroke, the program is
      executed  after pressing the enter key.                       }
                           uses crt;
                           var ans:char;
                           begin
                           clrscr;
                           writeln(' Select (1) IN (2) OUT ');
                           readln(ans);
                           case ans of
                           '1':begin
                                  gotoxy(12,12);writeln('Your inside');
                             end;
                           '2':begin
                                  gotoxy(12,12);writeln('Your outside');
                               end
                           else
                           writeln('select only 1 or 2');
                           end;
                           ans:=readkey;
                           end.

                           PROGRAM FORDO STATEMENT;
EXPLAINATIONS:
{ the program use x and y for gotoxy(x,y) to make a box
  x and y is a (Variable integer)
  writeln('²') is an output to screen device
  readln; - holds or pause the output for being displayed
  gotoxy  - x is the horizontal ----- of screen ( coordinates [ 1 to 80 ] )
          - y is the vertical   ||||| of screen ( coordinates [ 1 to 80 ] }
                           uses crt;
                           var x,y:integer;
                           begin
                           for x:=10 to 70 do
                           for y:=5 to 20  do
                           begin
                           gotoxy(x,y);writeln('²');
                           end;
                           readln;
                           end.

captian jaster

  • Guest
Re: How to define a record globally?
« Reply #6 on: October 19, 2010, 01:23:40 am »
Quote
continuation

    gotoxy(56,22);writeln('REMARK: ',unitrec[e-1].remark);
    gotoxy(8,22);writeln('TOTAL UNIT COST:');
    gotoxy(25,14);writeln(unitrec[e-1].unitnum);
    gotoxy(25,16);writeln(unitrec[e-1].name);
    gotoxy(25,17);writeln(unitrec[e-1].chasisnum);
    gotoxy(25,18);writeln(unitrec[e-1].enginenum);
    gotoxy(25,19);writeln(unitrec[e-1].buyer);
    gotoxy(25,20);writeln(unitrec[e-1].price:7:2);
    gotoxy(25,21);writeln(unitrec[e-1].deduct:7:2);
    gotoxy(25,22);writeln(unitrec[e-1].tcost:7:2);
    if unitrec[e-1].remark='SOLD' then
    begin
    gotoxy(12,15);writeln('  DATE SOLD: ',unitrec[e-1].datesold);
    end;
    end
    else
    begin
    gotoxy(59,13);textcolor(15);textbackground(0);
    writeln('RECORD NOT EXIST!');normvideo;
    gotoxy(78,14);ans:=readkey;exit;
    end;
    repeat
gotoxy(56,13);writeln('DELETE RECORD ! (Y/N)');
gotoxy(70,13);textcolor(15+16);textbackground(0);writeln('N');normvideo;
gotoxy(70,13);ans:=readkey;
    if upcase(ans)<>'Y' then exit;
    until upcase(ans)='Y';
    unitrec[e-1].unitnum:='';
    unitrec[e-1].name:='';
    unitrec[e-1].chasisnum:='';
    unitrec[e-1].enginenum:='';
    unitrec[e-1].buyer:='';
    unitrec[e-1].remark:='';
    unitrec[e-1].datearrive:='';
    unitrec[e-1].datesold:='';
    unitrec[e-1].price:=0;
    unitrec[e-1].deduct:=0;
    unitrec[e-1].tcost:=0;
recnum:=recnum-1;
xn:=0;
exit;
end;
Procedure Lister;
var
    xnum,xn,e:integer;
    xunitnum:string;
    c:boolean;
    function s:boolean;
    begin
    if xunitnum = unitrec[e].unitnum then
    s:=true
    else
    s:=false;
    end;
    begin
    xnum:=recnum;
    table;
    gotoxy(54,8);textcolor(15+16);textbackground(0);writeln('5');normvideo;
    e:=1;
    repeat
    c:=s;
    inc(e);
    until (c=true) or (e>maxunit);
    if (c=true) then
    begin
    window(1,14,80,25);
    gotoxy(2,0);writeln('³   UnitNo: -> UnitName: -> Remark:');
    gotoxy(2,0);writeln('³  ---------------------------------------------------------------------------');
    for e:=1 to xnum+((maxunit-1)-recnum) do
    begin
    gotoxy(2,5);writeln('          ',unitrec[e].unitnum,'     ->      ',unitrec[e].name,'      ->      ',
    unitrec[e].remark);
    ans:=readkey;
    gotoxy(2,5);writeln('                                                                              ');
    end;
    end
    else
begin
    gotoxy(54,13);writeln('<*> NO RECORD EXIST <*>');
    gotoxy(54,08);ans:=readkey;exit;
end;
window(1,1,80,25);
end;
procedure programmers;
begin
gotoxy(30,17);writeln('Programmed by:');
gotoxy(30,18);writeln('              Rocamora Roderick');
gotoxy(30,19);writeln('              Samonte Arlene');
gotoxy(30,20);writeln('              Butaslac Teofredo');
gotoxy(30,21);writeln('              Salenga Eva Alice');
gotoxy(30,22);writeln('Submitted to :');
gotoxy(30,23);writeln('              Engr. Noel Khu Amao');
end;
procedure status;
begin
programmers;
gotoxy(15,2);writeln('Limited Edition');
gotoxy(5,3);writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
gotoxy(5,4);writeln('º                                 º');
gotoxy(5,5);writeln('º  Maximum unit to input     : ',maxunit-1 ,'  º');
gotoxy(5,6);writeln('º  Number of Record inputed  : ',recnum,'  º');
gotoxy(5,7);writeln('º  Remaining records to input: ',(maxunit-1) - recnum,'  º');
gotoxy(5,8);writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
gotoxy(15,4);textcolor(15);textbackground(0);writeln('Record Analyzer');
gotoxy(43,17);writeln(':');gotoxy(43,22);writeln(':');normvideo;
gotoxy(22,4);textcolor(15+16);textbackground(0);writeln('A');normvideo;
end;
    procedure exitout;
    begin
    textcolor(15+16);textbackground(0);
    gotoxy(55,12);writeln('THANK YOU ENCODE AGAIN');
    normvideo;
    end;
    begin
    z;
    recnum:=0;
    xn:=0;
    repeat
    clrscr;
    status;
    gotoxy(50,1); writeln('ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿');
    gotoxy(50,2); writeln('³');
    textcolor(15);textbackground(0);
    gotoxy(53,2); writeln('NISSAN CARS INCORPORATED');
    normvideo;
    gotoxy(80,2); writeln('³');
    gotoxy(50,3); writeln('³            MENU             ³');
    gotoxy(50,4); writeln('³  (1) NEW ARRIVAL UNIT       ³');
    gotoxy(50,5); writeln('³  (2) UNIT SOLD (PULL-OUT)   ³');
    gotoxy(50,6); writeln('³  (3) QUERY/EDIT UNIT        ³');
    gotoxy(50,7); writeln('³  (4) QUERY/DELETE UNIT      ³');
    gotoxy(50,08);writeln('³  (5) LIST RECORD REMARK     ³');
    gotoxy(50,09);writeln('³  (6) QUIT                   ³');
    gotoxy(50,10);writeln('ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ');
    gotoxy(50,11);writeln('>>>SELECT A NUMBER (1.( ).6)<<<');
    gotoxy(73,11);ans:=readkey;
    case ans of
    '1':unitadd;
    '2':unitsold;
    '3':edit;
    '4':delete;
    '5':Lister;
    '6':;
    else
    gotoxy(55,15);writeln('>>> ERROR SELECTION <<<');
    ans:=readkey;
    end;
    until (ans='6');
    exitout;
    ans:=readkey;
    exit;
    end.

    SAMPLE PROGRAM <:Statement Application:>

                           PROGRAM LABEL/GOTO AND IF THEN...ELSE STATEMENT;
EXPLAINATIONS:
{ The program continues to operate until ( i is greaterthan equal to five )
  program usage: inc(i) - means increase i, if i=0 then increase i=1 to up}
                           label a;
                           var i:integer;
                           begin
                           i:=0;
                           a:
                           write('Welcome to my ( H N B ) program');
                           readln;
                           inc(i);
                           if i <=5 then
                           goto a
                           else if i>5 then
                           end.

                           PROGRAM REPEAT_UNTIL STATEMENT;
EXPLAINATIONS:
{ the program continues to ask until you press 'y' or 'Y'
  program usage: upcase(a)='Y'  - pressing small letter or capital letter
                 readln(a)      - use for inputing any kind of variable(Var)}
                           var a:char;
                           begin
                           repeat
                           write('Are you Welcome to my program? ( Y/N )');
                           readln(a);
                           until upcase(a)='Y';
                           end.

                           PROGRAM WHILEDO STATEMENT;
EXPLAINATIONS:
{ the program statement will not accept letters
  program usage: B is boolean( it can be true if the statement is true or
                                         false if the statement is not true.
  $i-           - input structure
  $i+           - output structure
B:=(ioresult=0) - output in B is now true because of (i)nput(o)output
                  is equal to Zero.                                  }
                           var B:boolean; { true or false }
                               numberonly:integer;
                           begin
                           B:false;
                           while not b do   { while not false says }
                           begin
                           {$i-} readln(numberonly); {$i+}
                           b:=(ioresult=0);
                           if not b then     { if not number typed then }
                           write('the number you dial is not on service')
                           else
                           write('its good to follow instruction');
                           readln;
                           end;

                           PROGRAM CASE...ELSE STATEMENT;
EXPLAINATIONS:
{ The statement of the program is to select only ( 1 or 2 )
  program usage : uses crt - uses the Cathod Ray Tube (in TV picture tube)
              ans:=readkey - waiting for any key to press without enter key
      not like readln(ans) - is dependent in keystroke, the program is
      executed  after pressing the enter key.                       }
                           uses crt;
                           var ans:char;
                           begin
                           clrscr;
                           writeln(' Select (1) IN (2) OUT ');
                           readln(ans);
                           case ans of
                           '1':begin
                                  gotoxy(12,12);writeln('Your inside');
                             end;
                           '2':begin
                                  gotoxy(12,12);writeln('Your outside');
                               end
                           else
                           writeln('select only 1 or 2');
                           end;
                           ans:=readkey;
                           end.

                           PROGRAM FORDO STATEMENT;
EXPLAINATIONS:
{ the program use x and y for gotoxy(x,y) to make a box
  x and y is a (Variable integer)
  writeln('²') is an output to screen device
  readln; - holds or pause the output for being displayed
  gotoxy  - x is the horizontal ----- of screen ( coordinates [ 1 to 80 ] )
          - y is the vertical   ||||| of screen ( coordinates [ 1 to 80 ] }
                           uses crt;
                           var x,y:integer;
                           begin
                           for x:=10 to 70 do
                           for y:=5 to 20  do
                           begin
                           gotoxy(x,y);writeln('²');
                           end;
                           readln;
                           end.
I'm pretty sure you couldve put the whole thing in a code bracket  ;D
Also
Code: Pascal  [Select][+][-]
  1. Type
  2.  TRec = RecordName
  3.   S:String;
  4.   Int:Integer;
  5.  end;
  6.  
  7.  TArr = Array Of RecordName;
  8. ...
  9. Var
  10.  Arr:TArr;
  11.  

code850

  • Newbie
  • Posts: 5
Re: How to define a record globally?
« Reply #7 on: October 19, 2010, 06:02:26 am »
Thanks a lot, now code is working.
I wonder why defining a record in the public declarations is not allowed.  It would be better to allow all user definitions in the public sector of the unit just to maintain consistency.

Cheers,

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to define a record globally?
« Reply #8 on: October 19, 2010, 07:17:30 am »
Your Welcome :D

eny

  • Hero Member
  • *****
  • Posts: 1658
Re: How to define a record globally?
« Reply #9 on: October 19, 2010, 07:43:51 am »
AS a sidenote: everything is much easier to read if you put (long) listings in a separate, uploaded file.
This reduces the risk that someone will quote the whole thing without really adding something to the quoted text.
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to define a record globally?
« Reply #10 on: October 19, 2010, 11:50:50 am »
Next time,

Thank you

 

TinyPortal © 2005-2018