Recent

Author Topic: Why does this integer not work in an array alteration?  (Read 4694 times)

Afrooman108

  • New Member
  • *
  • Posts: 26
Why does this integer not work in an array alteration?
« on: February 11, 2013, 11:02:08 pm »
E1:
Writeln('Choose seat character'); 
Readln(CH);                                         {Here the first letter of the array is decided}
Writeln('Choose seat number');
Readln(IP);                                          {This is the array number}

CH[IP].Surname:=Surname;                 {It struggles here With the IP variable)
CH[IP].name:=name;
CH[IP].date:=(Day,Month,Year);
CH[IP].az:=1;
__________
type
rec=record
Surname,name:string;
Date:string;
az:integer;
end;
__________

Var
  Fname, txt:string;
  Userfile:text;
  Q:Char;
  A:array[1..14] of rec;
  B:Array[1..16] of rec ;
  C:array[1..17] of rec  ;
  D:array[1..19] of rec   ;
  E:array[1..20] of rec    ;
  F:array[1..20] of rec     ;
  G:array[1..19] of rec      ;
  H:array[1..19] of rec       ;
  I:array[1..19] of rec        ;
  J:array[1..19] of rec         ;
  K:array[1..15] of rec          ;
  CH:char;
  IP:integer;
  P:integer                   ;
  Sel:string;
  Surname, Name, Date:string;
  Day,Month,Year:Integer;

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Why does this integer not work in an array alteration?
« Reply #1 on: February 11, 2013, 11:11:34 pm »
You can't CH[], because type of CH is not an array, but just char. You can't really refer to different arrays that easily, actually i can't find much of ways at all. You can use pointers and use case for 1 way:
Code: [Select]
var pCH: ^rec;

case CH of
  'A': pCH:=@A[IP];
 ..
end;
pCH^.Surname:=Surname;
pCH^.name:=name;
pCH^.date:=(Day,Month,Year);
pCH^.az:=1;
But it raises questions on why would you want to have so many arrays?

PS. There are many spaces before some ; line ends.
« Last Edit: February 12, 2013, 06:34:49 am by User137 »

jshand2010

  • Full Member
  • ***
  • Posts: 236
Re: Why does this integer not work in an array alteration?
« Reply #2 on: February 12, 2013, 06:18:05 am »
E1:

Writeln('Choose seat character'); 
Readln(CH);                                         {Here the first letter of the array is decided}
Writeln('Choose seat number');
Readln(IP);

SetLength(IP, sizeof(IP));                                          {This is the array number}

CH[IP].Surname:=Surname;                 {It struggles here With the IP variable)
CH[IP].name:=name;
CH[IP].date:=(Day,Month,Year);
CH[IP].az:=1;
__________
type
rec=record
Surname,name:string;
Date:string;
az:integer;
end;
__________

Var
  Fname, txt:string;
  Userfile:text;
  Q:Char;
  A:array[1..14] of rec;
  B:Array[1..16] of rec ;
  C:array[1..17] of rec  ;
  D:array[1..19] of rec   ;
  E:array[1..20] of rec    ;
  F:array[1..20] of rec     ;
  G:array[1..19] of rec      ;
  H:array[1..19] of rec       ;
  I:array[1..19] of rec        ;
  J:array[1..19] of rec         ;
  K:array[1..15] of rec          ;
  CH: array of char;
  IP: array of integer;
  P:integer                   ;
  Sel:string;
  Surname, Name, Date:string;
  Day,Month,Year:Integer;
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

Afrooman108

  • New Member
  • *
  • Posts: 26
Re: Why does this integer not work in an array alteration?
« Reply #3 on: February 12, 2013, 03:47:34 pm »
Ok, cheers. I will just use 11 if statements.

How can i use the STR() function to turn 3 integer variables into a date.

Day:int;
Month:int ;
Year:int;
Date:str;

Date:=STR(DAY, '/', Month, '/', Year);

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Why does this integer not work in an array alteration?
« Reply #4 on: February 12, 2013, 04:48:35 pm »
You can do:
Code: [Select]
Date:=inttostr(DAY)+ '/'+inttostr(Month)+'/'+inttostr(Year);
But we usually use TDateTime for storing dates.
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var date: TDateTime;
    y, m, d: Word;
begin
  y:=2013;
  m:=2;
  d:=12;
  date:=EncodeDate(y, m, d);
  writeln('Date is: '+DateToStr(date));
end;
On Linux, you have to add the unit "clocale" to uses section of *.lpr file to have correct formatting.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Afrooman108

  • New Member
  • *
  • Posts: 26
Re: Why does this integer not work in an array alteration?
« Reply #5 on: February 12, 2013, 05:14:02 pm »
Hi, this is great. I have opted for the INTTOSTR option but i get identifier not found.

I will use the other method now. But i get this often, I'm using CRT.

Cheers

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Why does this integer not work in an array alteration?
« Reply #6 on: February 12, 2013, 06:56:43 pm »
Most string functions require SysUtils added to uses list. But with a little search you would know which unit it comes from.

 

TinyPortal © 2005-2018