Kratkoe posobie po yazyku Informix-4GL
Soglasheniya o yazyke 4GL i nachal'nye ponyatiya.
Programma na yazyke 4GL mozhet sostoyat' iz neskol'kih fajlov
(modulej) s ishodnymi tekstami na 4GL. K nej tak zhe otnosyatsya
fajly s opisaniem ispol'zuemyh ekrannyh form, kotorye
kompiliruyutsya otdel'no. Imya kazhdogo modulya dolzhno imet'
rasshirenie .4gl (naprimer, module1.4gl), a imya fajla s
opisaniem ekrannyh form dolzhno imet' rasshirenie .per (naprimer,
form2.per).
Kazhdyj modul' soderzhit opisaniya peremennyh i neskol'ko
procedurnyh blokov function (podprogrammy) i report (bloki
pechati). V programme dolzhen byt' odin blok main - glavnyj
blok, nachinayushchijsya s klyuchevogo slova main. Na nego budet
peredavat'sya upravlenie pri starte programmy.
Format zapisi operatorov 4GL svobodnyj. Mozhno pisat' vse
podryad na odnoj stroke, odin operator na neskol'kih strokah,
slova operatorov mozhno razdelyat' proizvol'nym kolichestvom
probelov i kommentariev. Nikakimi znachkami (tipa ;) operatory
razdelyat' ne nuzhno. Okonchanie operatorov opredelyaetsya po
kontekstu.
Ves' nabor klyuchevyh slov yazyka zarezervirovan, ih nel'zya
zanimat' dlya drugih celej (na imena ob®ektov i peremennyh 4GL).
Kompilyatoru yazyka bezrazlichno, bol'shimi ili malen'kimi
bukvami pishutsya operatory. On ih ne razlichaet.
Kommentarii oboznachayutsya znakami { kommentarij },
ili znakom # - do konca stroki,
ili znakom -- (dva znaka minus) do konca stroki.
Ob®ekty, ispol'zuemye v Informix-4GL
1. Ob®ekty SQL 2. Peremennye 4GL 3. Programmnye
Imya bazy dannyh prostaya peremennaya funkciya
Imya tablicy peremennaya tipa "zapis'" otchet
Imya stolbca massiv metka
Imya indeksa
Imya psevdotablicy
Imya sinonima
( database-name prostye peremennye function )
( table-name peremennaya tipa zapis' report )
( column-name massivy label )
( index-name )
( view-name )
( synonim-name )
4. Imena operatorov 5. Ob®ekty ekrannogo obmena.
i kursorov
window
statement-id - izgotovlennyj operator form
cursor-name - kursor screen-field
screen-record
screen-array
1. IDENTIFIKATORY INFORMIX.
Kazhdyj ob®ekt 4GL imeet imya (identifikator) - eto slovo,
sostoyashchee iz bukv, cifr, i znakov podcherkivaniya (_),
nachinayushcheesya s bukvy ili znaka (_). V INFORMIX-4GL ne
razlichayutsya malen'kie i bol'shie bukvy. Poetomu i_Un103Tt i
I_UN103TT - odno i tozhe imya.
2. OBLASTI DEJSTVIYA IMEN PEREMENNYH:
LOKALXNAYA peremennaya - ob®yavlena vnutri bloka function, main,
report. Dejstvuet vnutri bloka, v kotorom ob®yavlena.
MODULXNAYA peremennaya dolzhna byt' ob®yavlena v samom nachale
modulya s ishodnym tekstom vne lyubogo bloka report, function ili
main. Dejstvuet vnutri vsego modulya (za isklyucheniem blokov, v
kotoryh eto imya pereob®yavleno i yavlyaetsya dlya nih lokal'nym).
GLOBALXNYE peremennye - ob®yavlyayutsya s pomoshch'yu oeratora GLOBALS
v nachale modulej. Dejstvuyut vo vseh modulyah s ishodnym tekstom,
v kotoryh est' sootvetstvuyushchee ob®yavlenie etih peremennyh.
3. Oblast' dejstviya imen KURSOROV i IZGOTOVLENNYH OPERATOROV ot
tochki ih ob®yavleniya (DECLARE, PREPARE) i do konca modulya.
4. Oblast' dejstviya imen OKON, FORM, FUNKCIJ, OTCHETOV - vo vsej
programme.
* V YAZYKE 4GL ESTX TAKIE OPERATORY *
Operatory SQL
sm. otdel'no fajl schoolsql
Organizaciya programmy
MAIN
FUNCTION
REPORT
Ob®yavleniya peremennyh
DEFINE
GLOBALS
Prisvoeniya
LET
INITIALIZE
Programmnye
CALL EXIT GOTO
RETURN FOR LABLE
CASE WHILE RUN
IF CONTINUE SLEEP
Perehvat preryvanij
WHENEVER
DEFER
Dinamicheskoe sozdanie operatorov
PREPARE EXECUTE FREE
Manipulyaciya "kursorom"
DECLARE
OPEN FOREACH PUT
CLOSE FETCH FLUSH
|krannyj obmen
MENU OPEN FORM DISPLAY ARRAY
OPTIONS DISPLAY FORM SCROLL
OPEN WINDOW CLOSE FORM INPUT ARRAY
CURRENT WINDOW DISPLAY PROMPT
CLEAR INPUT ERROR
CLOSE WINDOW CONSTRUCT MESSAGE
Generaciya otchetov
START REPORT
OUTPUT TO REPORT
FINISH REPORT
TIPY PEREMENNYH I OPERATORY OPISANIYA PEREMENNYH V 4GL
V yazyke 4GL imeyutsya prostye peremennye, peremennye tipa zapis'
i massivy. Prostye peremennye byvayut sleduyushchih tipov:
INTEGER CHAR(n) DATE
SMALLINT DECIMAL(m,n) DATETIME ed_vrem1 TO ed_vrem2
REAL MONEY(m,n) INTERVAL ed_vrem1 TO ed_vrem2
FLOAT
gde ed_vrem1, ed_vrem2 - edinicy izmereniya vremeni
{YEAR,MONTH,DAY,HOUR,MINUTE,SECOND,FRACTION(n)}
gde FLOAT = DOUBLE PRECISSION
Peremennaya tipa zapis' opisyvaetsya pri pomoshchi konstrukcii
RECORD ... END RECORD ili konstrukcii LIKE imya_tablicy.*
Peremennaya tipa massiv imeet opisatel' ARRAY [i,j,k] OF type,
gde type - tip prostoj peremennoj, konstrukciya RECORD, ili
konstrukciya ARRAY.
Dlya opisaniya peremennyh sluzhit operator DEFINE:
---------------------------------------------------------------
DEFINE simw char (200), j,i,k INTEGER, ff FLOAT
# Zdes' ob®yavleny simvol'naya peremennaya simw dlinoj 200 bajt,
# celye i,j,k, i ff - vos'mibajtovoe s plavayushchej tochkoj
DATABASE zawod
DEFINE doljno RECORD
# ob®yavlyaetsya zapis' doljno, sostoyashchaya iz 4 prostyh peremennyh
dolzn CHAR(20), # dolzhnost'
zarplmin LIKE kadry.zarplata,
zarplmax money(16,2), # zarplata
vakansii int # vakansii
END RECORD # Zdes' zakanchivaetsya ob®yavlenie zapisi doljno
# Peremennuyu mozhno o®yavit' s klyuchevym slovom LIKE column_name.
# peremennaya zarplmin poluchaet takoj zhe tip, chto i stolbec
# zarplata tablicy kadry iz bazy dannyh zawod
DEFINE rrr RECORD LIKE kadry.*
# Peremennuyu tipa zapis' tozhe mozhno ob®yavit' s klyuchevym slovom
# LIKE. Zdes' ob®yavlena zapis' rrr, soderzhashchaya elementy, imeyu-
# shchie te zhe samye nazvaniya i te zhe samye tipy chto i stolbcy
# tablicy kadry
---------------------------------------------------------------
|lementami zapisi mogut byt' massivy. Mozhno ob'yavit' massiv
elementov tipa RECORD.
---------------------------------------------------------------
DEFINE zap RECORD
a LIKE kadry.tabnom,
b array[8] OF REAL
END RECORD,
massiw ARRAY[2,15] OF RECORD
kolwo INT,
tip CHAR(8)
END RECORD
# massiw ob®yavlen kak massiv zapisej. Kazhdaya zapis' sostoit
# iz dvuh prostyh elementov - kolwo i tip
---------------------------------------------------------------
Indeksy massivov pishutsya v kvadratnyh skobkah. Na elementy
zapisej mozhno ssylat'sya po ego imeni, esli ne dopuskaetsya
dvusmyslennosti, inache ih neobhodimo utochnyat' imenem zapisi,
otdelyaya ego tochkoj (.) ot prostogo imeni.
---------------------------------------------------------------
# prisvoit' znachenie elementu masiva mozhno tak:
LET massiw[1,i+2].kolwo = zap.a + LENGTH(massiw[1,i+2].tip)
---------------------------------------------------------------
Dlya sokrashcheniya perechisleniya elementov v spiskah mozhno pol'zo-
vat'sya notaciej (*). Naprimer, strkt.* oznachaet vse elementy
zapisi strkt. A tak zhe notaciej THRU: (elementy zapisi ot i do)
---------------------------------------------------------------
SELECT kadry.* INTO strkt.* FROM kadry WHERE kadry.tabnom=i+j
SELECT * INTO strukt.b THRU strkt.e FROM kadry
---------------------------------------------------------------
Global'nye peremennye dolzhny imet' odinakovye ob®yavleniya
GLOBALS vo vseh modulyah programmy (v kotoryh ispol'zuyutsya).
Proshche vsego eto organizuetsya tak: zavoditsya otdel'nyj modul', v
kotorom nichego, krome ob®yavlenij GLOBALS net. A vo vseh ostal'-
nyh modulyah programmy ssylayutsya na etot fajl. Nizhe privoditsya
primer ob®yavleniya global'nyh peremennyh v fajle progrglob.4gl:
---------------------------------------------------------------
DATABASE zawod
GLOBALS
DEFINE zap RECORD LIKE kadry.*
DEFINE ext_count INT
. . .
END GLOBALS
---------------------------------------------------------------
Togda v ostal'nye moduli programmy, gde ispol'zuyutsya eti glo-
bal'nye peremennye, nado vklyuchit' strochku
---------------------------------------------------------------
GLOBALS "progrglob"
. . .
---------------------------------------------------------------
PODPROGRAMMNYE BLOKI (FUNKCII).
V yazyke 4GL pri programmirovanii funkcij (podprogramm) ispol'-
zuyutsya operatory function. Vse argumenty funkcii dolzhny byt'
ob®yavleny. Argumenty peredayutsya po znacheniyu. Esli funkciya vozv-
rashchaet kakie-libo znacheniya, to pri vyzove ee nuzhno vospol'zo-
vat'sya v operatore CALL predlozheniem RETURNING s perechisleniem
peremennyh, v kotorye vozvrashchaetsya znachenie. Nizhe privoditsya
sootvetstvuyushchij fragment programmy.
---------------------------------------------------------------
FUNCTION stroka(rec)
DEFINE rec RECORD i int, st char(256) END RECORD
RETURN st clipped,"avtoprobega"
END FUNCTION
. . .
MAIN
. . .
CALL stroka(rec1.*) RETURNING simw
. . .
LET simw=stroka(7,"Privet uchastnikam ")
# Esli funkciya vozvrashchaet odno znachenie, to ee imya mozh-
# no ispol'zovat' v vyrazheniyah.
MESSAGE simw
. . .
END MAIN
---------------------------------------------------------------
Na ekrane pol'zovatel' uvidit:
+--------------------------------------------------------+
|Privet uchastnikam avtoprobega |
| |
| |
| |
+--------------------------------------------------------+
PRIMERY ISPOLXZOVANIYA PROGRAMMNYH OPERATOROV
Operator bezuslovnogo perehoda dejstvuet v predelah modulya.
---------------------------------------------------------------
GOTO metka
. . .
LABEL metka: . . .
---------------------------------------------------------------
Operator vybora.
---------------------------------------------------------------
CASE
WHEN iscreen=1
current window is w1
WHEN iscreen=2
current window is w2
let iscreen=1
OTHERWISE
current window is SCREEN
END CASE
CASE (a+b) # Drugoj format operatora CASE
WHEN 1
message "a=",a
WHEN 2
message "b=",b
END CASE
---------------------------------------------------------------
Uslovnyj operator.
---------------------------------------------------------------
IF str = "zavershit'" OR y<0 THEN exit program
# Ne zabyvajte v konce kazhdogo uslovnogo
# operatora stavit' END IF.
END IF
---------------------------------------------------------------
Operator cikla.
---------------------------------------------------------------
FOR I= i1 TO 23
let a[i]=0
if b[i]=100 then
EXIT FOR
END IF
END FOR
---------------------------------------------------------------
Cikl "poka".
---------------------------------------------------------------
WHILE ff > 3 or nn="proba"
PROMPT "Vvedite chislo " for n
let i=n+1
message "A u menya ",i,", bol'she. Vy proigrali."
SLEEP 5
RUN "rm *" WITHOUT WAITING
END WHILE
---------------------------------------------------------------
* DINAMICHESKOE IZGOTOVLENIE OPERATOROV SQL. KURSORY *
Operatory PREPARE i EXECUTE prednaznacheny dlya dinamicheskogo (vo
vremya vypolneniya programmy) izgotovleniya i vypolneniya operato-
rov yazyka SQL (ne 4GL !!!).
V privedennom nizhe fragmente v otvet na zapros pol'zovatel'
smozhet vvesti s klaviatury stroku s operatorom yazyka SQL
(Pust', naprimer, on vvedet stroku: DROP DATABASE buhgalteriq).
Programma izgotovit iz etoj stroki nastoyashchij operator i vypol-
nit ego s pomoshch'yu operatora EXECUTE. Esli pri vypolnenii zare-
gistrirovana oshibka, o chem soobshchit ustanovlennyj v otricatel'-
noe znachenie kod zaversheniya status, pol'zovatelya snova poprosyat
vvesti operator.
---------------------------------------------------------------
DEFINE stroka char(200)
MAIN
. . .
LABEL METK2:PROMPT "vvedite operator yazyka SQL: " FOR stroka
WHENEVER ERROR CONTINUE # Vklyuchit' rezhim "V sluchae
# oshibki prodolzhit' vypolnenie
# programmy"
PREPARE st1 FROM stroka # Izgotovit' operator iz
# simvol'noj stroki
EXECUTE st1 # Vypolnit' izgotovlennyj operator
IF status<0 THEN
ERROR "oshibka nomer ", status, " v vashem operatore"
GOTO metk2
END IF
WHENEVER ERROR STOP # Vosstanovit' rezhim
# "V sluchae oshibki prervat'
# vypolnenie programmy"
. . .
END MAIN
---------------------------------------------------------------
V sistemnuyu peremennuyu status pomeshchaetsya kod vypolneniya kazhdogo
operatora 4GL (status=0 esli vse normal'no, status<0 esli proi-
zoshla oshibka). Peremennaya status mozhet proveryat'sya posle lyubogo
operatora programmy i v zavisimosti ot ee znachemogut predprini-
mat'sya kakie-libo dejstviya.
Esli zapros k tablice vozvrashchaet neskol'ko (bol'she odnoj)
strok, to dlya ih obrabotki ispol'zuetsya tak nazyvaemyj kursor -
ukazatel' vo mnozhestve strok, vybrannyh operatorom SELECT. Ope-
ratorom DECLARE ob®yavlyaetsya kursor dlya zaprosa, operatorom OPEN
etot zapros fakticheski vypolnyaetsya i vybrannye stroki vydelyayut-
sya. Kursor ustanavlivaetsya na pervuyu iz vybrannyh strok. S po-
moshch'yu operatora FETCH vy mozhete brat' ocherednuyu stroku, na ko-
toruyu ukazyvaet kursor, i pomeshchat' ee v svoi programmnye pere-
mennye. Kursor posle etogo smeshchaetsya na sleduyushchuyu stroku.
S pomoshch'yu konstrukcii ciklicheskoj FOREACH imya_kursora ... END
FOREACH mozhno perebrat' vse stroki, vybrannye operatorom
SELECT. Operator OPEN v etom sluchae ne nuzhen.
---------------------------------------------------------------
DATABASE zawod
DEFINE zap RECORD LIKE kadry.*
DECLARE curs1 CURSOR FOR
select * from kadry where datarovd>"9/25/1973"
# v cikle FOREACH vyvodim na ekran vse stroki tablicy kadry,
# v kotoryh stolbec datarovd soderzhit datu posle 25 sentyabrya
# 1973 goda.
FOREACH curs1 INTO zap.* # Berem ocherednuyu stroku i po-
# meshchaem ee v zapis' zap
MESSAGE zap.* # Vyvodim zapis' zap na ekran
PROMPT "Eshche ?" FOR CHAR c
END FOREACH # Konec cikla FOREACH
---------------------------------------------------------------
V sleduyushchem primere stroki vybiraemye iz tablicy kadry cherez
kursor curs2 pomeshchayutsya v massiv z1 (no ne bolee 100 strok).
---------------------------------------------------------------
DATABASE zawod
DEFINE z1 ARRAY[100] OF RECORD LIKE kadry.*, counter int
DECLARE curs2 CURSOR FOR SELECT * FROM kadry
WHERE datarovd<"9/26/1973"
OPEN curs2
FOR counter=1 TO 100
FETCH curs2 INTO z1[counter].*
# vzyat' ocherednuyu stroku i pomestit' ee v sleduyushchij element
# massiva z1
IF status=NOTFOUND THEN
# esli vybrannye sroki konchilis', zakonchit' cikl
EXIT FOR
END IF
END FOR
LET counter=counter-1
MESSAGE "V massiv z1 prochitano ",counter, " zapisej"
---------------------------------------------------------------
|tot primer demonstriruet eshche odno ispol'zovanie peremennoj
status. Esli operator FETCH pytaetsya vzyat' sroku iz kursora
kogda tot uzhe pust, to znachenie peremennoj status ustanavliva-
etsya ravnym simvolicheskoj konstante NOTFOUND, imeyushchej znachenie
100. Poetomu mozhno proveryat' znachenie status posle operatora
FETCH i esli ono ravno 100, to prekratit' chtenie strok iz opus-
tevshego kursora.
V dannom primere pol'zovatel' sam dolzhen vvesti usloviya, po ko-
torym budut najdeny stroki v tablice ceh. On, naprimer, mozhet
vvesti: "nomerceh>15 and nomerceh<23". Programma pricepit eto
uslovie k stroke, v kotoroj zapisan SELECT operator, poluchit
strochku "SELECT * FROM ceh WHERE nomerceh>15 and nomerceh<23",
izgotovit iz nee operator, i dlya etogo izgotovlennogo operatora
SELECT ob®yavit kursor. Dal'she dejstviya analogochny predydushchemu
primeru.
---------------------------------------------------------------
DEFINE z2 ARRAY[100] OF RECORD LIKE ceh.*,
counter int, simw char(200)
PROMPT "dopishite operator SELECT * FROM ceh WHERE " FOR simw
IF LENGTH(simw)=0 THEN
LET simw="TRUE"
END IF
LET simw="SELECT * FROM ceh WHERE ", simw CLIPPED
PREPARE st2 FROM simw
DECLARE cs2 FOR st2
let counter=1
FOREACH cs2 INTO z2[counter].*
LET counter=counter+1
IF counter>100 THEN
EXIT FOREACH
END IF
END FOREACH
LET counter=counter-1
MESSAGE "V massiv z2 prochitano ",counter, " zapisej"
---------------------------------------------------------------
* PROGRAMMIROVANIE |KRANNOGO OBMENA * .
V lyuboj moment vremeni na ekrane terminala sushchestvuet TEKUSHCHEE
okno, cherez kotoroe i vypolnyaetsya vvod/vyvod vashej programmy. S
oknom svyazany ispol'zuemye pri vvode i vyvode atributy (napri-
mer, green, revers, underline i t.p.) i nomera strok okna, is-
pol'zuemyh operatorami MESSAGE, PROMPT i ERROR dlya vyvoda.
Pri otkrytii novogo okna ono stanovitsya tekushchim i i ves' vvod/
vyvod budet napravlyat'sya uzhe v nego.
V okno mozhno vyvesti ekrannuyu formu, kotoraya, predstavlyaet so-
boj nabor ekrannyh polej, imeyushchih imena, i v eti polya (iz etih
polej), obrashchayas' k nim po imeni, mozhno vyvodit' (vvodit') dan-
nye s pomoshch'yu operatora DISPLAY (INPUT). |krannye polya mozhno
ob®edinyat' v ekrannye zapisi. Opisanie ekrannyh polej i samoj
formy raspolagaetsya otdel'no ot programmy v fajle opisaniya ek-
rannoj formy.
Nizhe priveden primer programmy, illyustriruyushchij rabotu s oknami.
---------------------------------------------------------------
OPEN WINDOW wind1 AT 2,30 WITH 10 ROWS, 40 COLUMNS
ATTRIBUTE(BORDER, REVERSE, MESSAGE LINE FIRST)
# tekushchim oknom yavlyaetsya wind1
. . .
OPEN WINDOW wind2 AT 5,15 WITH FORM "schoolp"
ATTRIBUTE(GREEN,PROMPT LINE LAST,
MESSAGE LINE LAST, FORM LINE FIRST)
# tekushchim oknom yavlyaetsya wind2
CLEAR WINDOW wind1
. . .
CURRENT WINDOW IS wind1
# tekushchim oknom yavlyaetsya wind1
OPEN FORM form1 from "schoolp" # Inicializirovat' formu form1
# Vzyav ee opisanie iz fajla
# schoolp.frm
DISPLAY FORM form1 # Vyvesti formu form1 v tekushchee okno
# t.e. v wind1
---------------------------------------------------------------
V rezul'tate raboty etih operatorov na ekrane terminala
poyavitsya priblizitel'no takaya kartinka:
+-------------------------------------------------------------+
| +----------------------------------------+ okno |
| |znachenie ravno 8 | |wind1 |
| +---------------------------------------+ | | |
| | ceh [ 2] [litejnyj ] | |<-+ |
| | tab.nomer [26 ] | | okno |
| | familiya [Petrov U.E. ] | | | wind2|
| | dolzhnost' [brigadir ] | | | |
| | zarplata [$340 ] |<--------+ |
| | data rozhdeniya [31.12.1952] | | |
| | | | |
| +---------------------------------------+ | |
| | 789 | |
| +----------------------------------------+ |
| |
|net takih |
+-------------------------------------------------------------+
Operatory MENU. MESSAGE. PROMPT.
V rezul'tate raboty fragmenta programmy
---------------------------------------------------------------
let sta_return=podtwervdenie(" V samom dele reshili zakonchit'? ")
...
function podtwervdenie(stroka)
define stroka char(38) , kod_wozwr int
open window podtwervdenie AT 11,10 WITH 4 rows, 39 columns ATTRIBUTE(border)
display stroka at 4, 2 attribute (reverse)
menu " "
command key("Y") " Yes " "Dejstvitel'no Da."
let kod_wozwr=1
exit menu
command key("N",ESC) " No " "Net, vernut'sya obratno."
let kod_wozwr=0
exit menu
command key("A") " Abort " "Otmenit'. I konchit'."
let kod_wozwr=-1
exit menu
end menu
close window podtwervdenie
return kod_wozwr
end function
---------------------------------------------------------------
na ekrane v tekushchem okne poyavitsya takoe menyu
+---------------------------------------+
| : Yes No Abort |
|Dejstvitel'no Da. |
| |
| V samom dele reshili zakonchit'? |
+---------------------------------------+
Operator OPTIONS mozhet ustanovit' novye rezhimy dlya vvoda vyvo-
da, esli vas ne ustraivayut zadannye po umolchaniyu.
---------------------------------------------------------------
OPTIONS MESSAGE LINE 23,
HELP FILE "h4gl.txt", HELP KEY CONTROL-T,
DISPLAY ATTRIBUTE(REVERSE, UNDERLINE)
---------------------------------------------------------------
Operator MESSAGE vyvodit stroku znachenij na ekran na message
line. Argumentami MESSAGE mogut byt' peremennye i konstanty, no
ne vyrazheniya.
---------------------------------------------------------------
let ttmm=CURRENT
message "Moskovskoe vremya ", ttmm
error "Dannyh bol'she net, prochitanno ", n, " strok"
---------------------------------------------------------------
Operator ERROR delaet tozhe, chto i MESSAGE, tol'ko so zvonkom i
s atributom REVERSE. Soobshchenie vyvoditsya na 24-yu stroku ekrana.
Operator PROMPT vyvodit na ekran display-list - spisok znachenij
peremennyh i konstant, i vvodit posle etogo s klaviatury znache-
nie v ukazannuyu vsled za klyuchevym slovom FOR peremennuyu.
---------------------------------------------------------------
PROMPT "Da ili net ?" FOR answer
ON KEY (CONTROL-U)
LET answer=wozderv()
EXIT PROMPT
END PROMPT
---------------------------------------------------------------
Mozhno vklyuchit' v PROMPT kontrol'nye bloki, vypolnyayushchiesya pri
nazhatii zadannyh klavish. Esli v dannom primere vo vremya vvoda
pol'zovatel' nazhmet klavishu CTRL-U to vypolnyatsya operatory iz
ON KEY predlozheniya: budet vyzvana funkciya wozderv() a zatem
prervan operator PROMPT, ne zavershiv vvoda.
Operatory obmena s ekrannoj formoj DISPLAY i INPUT
Operator DISPLAY vyvodit dannye v polya ekrannoj formy.
---------------------------------------------------------------
DISPLAY a,b,zap[i].nomerceh TO pole1,fscr.* ATTRIBUTE(BOLD)
---------------------------------------------------------------
Esli imena vyvodimyh peremennyh sovpadayut s imenami ekrannyh
polej v tekushchej ekrannoj forme, to mozhno primenit' klyuchevoe
slovo BY NAME.
---------------------------------------------------------------
DISPLAY BY NAME fio, dolvnostx
---------------------------------------------------------------
Operator INPUT ispol'zuetsya dlya vvoda znachenij cherez polya
ekrannoj formy. Mozhno predusmotret' dopolnitel'nye dejstviya pri
vvode. Dlya etogo v operator mozhno vklyuchit' kontrol'nye bloki
AFTER, BEFORE, ON KEY.
---------------------------------------------------------------
INPUT kadr.* FROM fio, dolvnostx, nomerceh
BEFORE FIELD nomerceh
message "Segodnya obsluzhivayutsya ceha 5 i 6"
sleep 2
message ""
AFTER FIELD nomerceh
IF kadr.nomerceh > 6 then
MESSAGE "Net takogo ceha, povtorite"
NEXT FIELD NOMERCEH
ENF IF
END INPUT
---------------------------------------------------------------
CHasto primenyaemyj v 4GL metod vyvoda dannyh iz tablicy na
ekran shematicheski mozhno izobrazit' tak:
+-D-I-S-K----+ kursor
| +--------+ | operatory +---------------+
| | +-------------------> vybrannye |
| |tablica | | DECLARE FOR | |
| | | | SELECT-kursor| stroki |
| | | | i OPEN | |
| +--------+ | +-+-------------+
| | operatorami FETCH
| | ili FOREACH
+------------+ |
+--V------------+
+-T-E-R-M-I-N-A-L---------+ | programmnyj |
| | | massiv |
|+-----------------------+| +--+------------+
|| || ope|rator DISPLAY
|| [ ] || ili| DISPLAY ARRAY
|| [ ekrannyj ] || |
|| [ massiv ] <-------+
|| [ ] ||
|+-----------------------+|
+-------------------------+
Fragment, realizuyushchij okoshko podskazki.
Nizhe priveden primer programmirovaniya podskazki (v
processe interaktivnogo dialoga) s ispol'zovaniem ekrannogo
massiva. Tablica ceh soderzhit dva stolbca: nomer ceha i ego
nazvanie. V privedennom fragmente vyzyvaetsya funkciya wyborceh,
kotoraya vyvodit soderzhimoe tablicy ceh v ekrannyj massiv.
Pol'zovatel' peredvigaet kursor na nazvanie nuzhnogo emu ceha i
nazhimaet klavishu CR. Podprogramma opredelyaet nomer ceha i
vozvrashchaet ego vyzyvayushchej programme.
---------------------------------------------------------------
DATABASE zawod
. . .
let nc= wyborceh()
. . .
FUNCTION wyborceh() # Vybor ceha, dlya vneseniya izmenenij
DEFINE counter int
DEFINE ceharr ARRAY[25] OF RECORD # massiv dlya hraneniya
nomerceh int, # nomerceha dannyh iz tablicy
nameceh char(20) # nazvanie ceha ceh
END RECORD
# Otkryt' okno s ramkoj i vyvesti v nego ekrannuyu formu cehform
OPEN WINDOW cehwind AT 4 ,6 WITH FORM "cehform"
ATTRIBUTE(BORDER)
# Ob®yavit' kursor dlya vybora soderzhimogo iz tablicy ceh
DECLARE cehcurs CURSOR FOR
SELECT * FROM ceh ORDER BY nomerceh
# Vypolnit' zapros i vse vybrannye stroki pomestit' v program-
# nyj massiv ceharr
LET counter = 0
FOREACH cehcurs INTO ceharr[counter+1].*
LET counter = counter + 1
IF counter >=25 THEN EXIT FOREACH END IF
END FOREACH
# schetchik counter raven fakticheskomu chislu strok vydannyh v
# kursor
MESSAGE "Vyberite ceh i nazhmite CR"
# Vyvesti v ekrannyj massiv cehscreen v ekrannoj forme cehform
# counter pervyh strok iz programmnogo massiva ceharr
call set_count(counter)
DISPLAY ARRAY ceharr TO cehscreen.*
ON KEY (CONTROL-M) EXIT DISPLAY
END DISPLAY
# Prervat' pokaz ekrannogo massiva pri nazhatii klavishi CR
# zakryt' okno s ekrannoj formoj cehform
CLOSE WINDOW cehwind
let counter=arr_curr() #nomer stroki massiva,
#na kotorom nazhato CR
RETURN ceharr[counter].nomerceh #nomer ceha,
#na kotorom nazhato CR
END FUNCTION
---------------------------------------------------------------
A eto pol'zovatel' uvidit na ekrane:
+----------------------------+
|nomer ceh |
|[3 ] [tokarnyj ]|
|[4 ] [garazh ]|
|[5 ] [konyushnya ]|
|[6 ] [stolovaya ]|
|[ ] [ ]|
|Vyberite ceh i nazhmite CR |
+----------------------------+
Opisanie i kompilyaciya ekrannyh form
V privedennom vyshe fragmente ispol'zovana ekrannaya forma
cehform.per. Nizhe privedeno ee opisanie. |to opisanie dolzhno
lezhat' v fajle cehform.per i dolzhno byt' otkompilirovano kompi-
lyatorom ekrannyh form Informix'a form4gl.
Opisanie ekrannoj formy cehform.per
---------------------------------------------------------------
DATABASE zawod
SCREEN
{
nomer ceh
[f00] [f001 ]
[f00] [f001 ]
[f00] [f001 ]
[f00] [f001 ]
[f00] [f001 ]
}
TABLES
ceh
ATTRIBUTES
f00 = ceh.nomerceh;
f001 = ceh.nameceh;
INSTRUCTIONS
screen record cehscreen[5] (ceh.*)
END
---------------------------------------------------------------
V sekcii DATABASE ukazana baza dannyh; v sekcii SCREEN
zadana kartinka, kotoraya budet risovat'sya na ekrane; V TABLES
ukazyvayutsya tablicy, v ATRIBUTES ukazyvayutsya imena ekrannyh
polej, (i, vozmozhno, ih atributy) a v INSTRUCTIONS ob®yavlen
ekrannyj massiv cehscreen v pyati strokah iz dvuh polej
(nomerceh i nameceh)
V kachestve primera nizhe privoditsya funkciya, realizuyushchaya
prostejshij kal'kulyator. Vozvrashchaet znachenie vychislennogo
vyrazheniya. Skompilirujte ee samostoyatel'no i posmotrite
otladchikom, kak ona rabotaet.
---------------------------------------------------------------
function kalkulator() # Kal'kulyator
define wyravenie, kalkulator char(64), kolichestwo int
define stroka_kalkulatora char(200)
define beep char(1)
let beep=ascii 7
open window kalkulator at 2,2 with form "kalkulator"
attribute(border, form line first)
input by name wyravenie, kalkulator without defaults
before field kalkulator
let stroka_kalkulatora=
"select count(*),",wyravenie," from systables"
whenever error continue
prepare kalkulqtor_operator from stroka_kalkulatora
if status<0 then
display beep to kalkulator
display "Nepravil'noe vyrazhenie" to kalkulator
next field wyravenie
end if
declare kalkulator cursor for kalkulqtor_operator
foreach kalkulator into kolichestwo, kalkulator
if status<0 then
display beep to kalkulator
display "Nepravil'noe vyrazhenie" to kalkulator
next field wyravenie
end if
end foreach
whenever error stop
display kalkulator to kalkulator
next field wyravenie
end input
close window kalkulator
return kalkulator
end function
---------------------------------------------------------------
Ispol'zovannaya v podprogramme ekrannaya forma dolzhna byt'
opisana v fajle kalkulator.per i otkompilirovana pri pomoshchi
kompilyatora form4gl.
---------------------------------------------------------------
DATABASE formonly
SCREEN
{
Kal'kulyator. CHtoby zakonchit' nazhmite ESC
[wyravenie ]
[kalkulator ]
}
ATTRIBUTES
wyravenie =formonly.wyravenie;
kalkulator=formonly.kalkulator;
END
---------------------------------------------------------------
Last-modified: Tue, 25 Nov 1997 07:26:02 GMT