Sign in Join
Wiki copytemporary

Record/fi: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Record/fi

OldNewLine
1+**Record** eli tietue on hyvin jäsennelty tietotyyppi. Niitä käytetään laajalti Pascal:ssa. Niillä kootaan tiedot yhteen loogisesti eli se on loogisesti yhteenkuuluvien tietoalkioiden muodostama kokonaisuus.
2+
3+Monet yksinkertaiset tietorakenteet, kuten taulukot tai joukot koostuvat osista (tietoalkioista) jotka kaikki ovat samaa tyyppiä. Tietue eli Record voi koostua monista eri osista, ne voi olla eri tyyppiä ja ne voivat olla valtavan monimutkaisia. Tietueen osia kutsutaan kentiksi.
4+
5+Record on Pascalin [[Reserved word|varattu sana]].
6+
7+## Määrittely
8+
9+### Vakiorakenne
10+
11+``` pascal
12+type
13+ TMember = record
14+ firstname, surname : string;
15+ address: array [1..3] of string;
16+ phone: string;
17+ birthdate: TDateTime;
18+ paidCurrentSubscription: boolean
19+ end;
20+```
21+
22+### Muuttuva rakenne
23+
24+Vieläkin monimutkaisempia rakenteita voi olla, esim:
25+
26+``` pascal
27+type
28+ maritalStates = (unmarried, married, widowed, divorced);
29+ TPerson = record
30+ (* CONSTANT PART *)
31+ (* of course records may be nested *)
32+ name: record
33+ first, middle, last: string;
34+ end;
35+ sex: (male, female);
36+ (* date of birth *)
37+ dob: TDateTime;
38+ (* VARIABLE PART *)
39+ case maritalStatus: maritalStates of
40+ unmarried: ( );
41+ married, widowed: (marriageDate: TDateTime);
42+ divorced: (marriageDate, divorceDate: TDateTime;
43+ isFirstDivorce: boolean)
44+ end;
45+```
46+
47+Muuttuvan osan kentät ovat käytettävissä vain jälkeen tehtävän riippuen muuttujan. Se ei vahingoita onko kenttä marriageDate määritetty monta kertaa.
48+
49+## Osoittaminen
50+
51+### Kentät
52+
53+Yksittäisiä kenttiä osoitetaan laittamalla piste tietueen nimen ja kentän nimen väliin.
54+
55+``` pascal
56+ a.firstname := 'George';
57+ a.surname := 'Petersen';
58+ a.phone := '789534';
59+ a.paidCurrentSubscription := true;
60+```
61+
62+Vaihtoehtoisesti kokonaista sarjaa kenttiä voidaan osoittaa käyttämällä [[With]]-rakennetta:
63+
64+``` pascal
65+with a do
66+ begin
67+ firstname := 'George';
68+ surname := 'Petersen';
69+ phone := '789534';
70+ paidCurrentSubscription := true
71+ end;
72+```
73+
74+### Ilmentymä
75+
76+A tietuetta käsitellään ohjelmassa yhtenä kokonaisuutena. Esimerkiksi koko tietue voidaan kopioida (jos kopio on samaa tyyppiä) näin:.
77+
78+``` pascal
79+var
80+ a, b: TMember;
81+
82+(* main program *)
83+begin
84+ { ... assign values to the fields in record a .. }
85+ b := a
86+ { now b holds a copy of a }
87+ { don't get confused with references: }
88+ { a and b still point to different entities of TMember }
89+end.
90+```
91+
92+## Vakiotietueet
93+
94+``` pascal
95+
96+type
97+ //tietueen määrittely
98+ TSpecialDay = record
99+ DayName : string;
100+ month : integer;
101+ day : integer;
102+ end;
103+
104+const
105+
106+ // TSpecialDay vakiomäärittely
107+ ChristmasDay : TSpecialDay =
108+ (
109+ DayName : 'Christmas Day';
110+ month : 12;
111+ day : 25;
112+ );
113+```
114+
115+## Katso myös
116+
117+- [[Basic Pascal Tutorial/Chapter 5/Records|Records]], tutorial that covers records
118+
119+---
120+*From the Free Pascal wiki, page "Record/fi", as it stood on 2023-01-25 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history