Printer xossalari:
•
EndDoc usuli bilan grafik ma’lumot printerga yuboriladi.
Print Demo
P rinl ln lo ri m ndr = => P fin lc r p rin ts lc x t in lc x t m o d c I-]
P rin t lo rm
Dastur matni:
Unit Pri_form;
interface
uses
TForml = class(TForm)
Buttonl: TButton;
Labell: TLabel;
Label2: TLabel;
Bevell: TBevel;
Button2: TButton;
Bevel2: TBevel;
Button3: TButton;
Label3: TLabel;
Panell: TPanel;
Imaoel: Tlmage;
procedure ButtonlClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Forml: TForml;
implementation
{$R *.DFM}
To_Prn : TextFile;
Begin
Buttonl.Enabled:=False;
AssignPrn(To_Prn);
Rewrite(To_Pm);
Writeln(To_Prn, Label2.Caption);
Procedure TForml.Button2Click(Sender: TObject);
Begin
149
Button2.Enabled:=False;
Forml.Print;
end;
BeginDoc;
Canvas.Draw(0,0,Image 1. Picture. Bitmap);
NewPage;
Canvas.StretchDraw(Rect(0, 0,300, 300),
Image1.Picture.Bitmap);
EndDoc;
S a v o 11 a r
YI.DELPHI TILINING IMKONIYATLARI
6.1.Yozuvlarni faylga yozish va fayldan o‘qish
Yozuvlami faylda saqlash mumkin. Dastuming o‘zgaruvchi yozuv
qiymatini faylda saqlash uchun yozuv turidagi faylni e’lon qilish
kerak. Misol uchun:
Type
TRerson = record
f riame: string [20] ;
l name: string[20];
address: string[50]; end; var
f: file of TPerson;
Instmksiya komponentalari TPerson turidagi yozuvlar bolgan
faylni e’lon qiladi. Yozuvlar fayli bilan ishlash oddiy fayllar bilan
ishlashdan farq qilmaydi.
Yozuvlarni faylgayozish
u s s x m s a m w m
Sfalwnw
|
MMMKlll
3
■.piilllluI
I----------- 3
MMltJ
IC K*n»ii»h
Killmnli
~oj*j
Foydalanuvchi tomo-
nidan kiritiluvchi muso-
baqa natijalarini faylga
yozuvchi dastumi ko‘rib
chiqamiz. M a’lumotlar
dialog oynasiga kiritilib,
komponentalari TMedal
turidagi yozuvlar bolgan
faylda saqlanadi.
Sportsmen familiyasini
kiritish uchun Edit kom-
ponentasi ishlatiladi. Sport
turi va mamlakat nomini
kiritish uchun ComboBox
komponentasi ishlatiladi.
Ro‘yxatnihosil qilish uchun
Object Inspector oynasida
Items xossasini tanlab, uch
nuqtali tugmasini bosib,
ro‘yxat muharririni aktiv-
lashtirish lozim.
151
String list EJitor
5 t o n
zbekis:on
PciS-Siyy
LJ
£odeEd)«
C * Y ti
Dastur matni:
Unit Unitl;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ExtCtrls;
Type
TForml = class(TForm)
Editl: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Buttonl: TButton;
ComboBoxl: TComboBox;
ComboBox2: TComboBox;
RadioGroupl: TRadioGroup;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure ButtonlClick(Sender: TObject);
private
152
{ Private declarations } public
{ Public declarations } end;
TKind = (GOLD, SILYER, BRONZE);
TMedal=record
country: string[20];
sport: string[20];
person: string[40];
kind: TKind;
end;
Var
Forml: TForml;
f: file of TMedal;
implementation
{$R *.DFM}
procedure TForml.FormActivate(Sender: TObject);
var
resp : word;
begin
AssignFile(f,' a:\medals.db');
{$1-}
Reset (f);
Seek(f, FileSize(f));
{$1+}
if IOResult = 0
then buttonl.enabled:=TRUE;
else begin
resp:=MessageDlg('
begin
with medal do begin
country := ComboBoxl.Text;
sport := ComboBox2.Text;
person := Editl.Text;
case RadioGroupl.ItemIndex of
0: kind := GOLD;
1: kind := SILVER;
2: kind := BRONZE;
end;
end;
write(f,medal);
end;
procedure TForml.FormClose(Sender: TObject;
var
Action: TCloseAction);
begin
CloseFile(f);
end.
Bu dasturda TForml.FormActivate protsedurasi faylni ochadi.
Fayl matnli bolmagani uchun Rewrite protsedurasi bilan ochilib
Seek protsedurasi ko‘rsatgichni fayl oxiriga o‘rnatadi.
TForml.ButtonlClickprotsedurasi faylgayozuv qo‘shishni amalga
oshiradi.
TFormLFormClose protsedurasi faylni berkitadi.
Ko‘rilgan dasturda ro‘yxat loyihalashtirish jarayonida o‘rnatiladi.
Dastur bajarilishjarayonida ro‘yxatni o‘rnatish uchun items xossasiga
Add usulini qollash kerak.
Masalan:
Forml.ComboBoxl.Item.Add(' Rossiya');
FormLComboBoxl .Item.Add(' Avstriya');
Forml.ComboBoxl.Item.Add(' Germaniya');
Forml.ComboBoxl.Item.Add(' Fransiya');
Fayldan yozuvni o‘qish
Quyidagi dasturda fayl ochilib, hamma mamlakatlar yoki tanlangan
mamlakat sportchilari tomonidan yutib olingan medallar ro‘yxatini
ekranga chiqaradi.
154
Quyidagi jadvalda forma komponentalari xossalari berilgan:
Xossa
Qiymat
RadioButtonl.Checked
Labell.Enabled
ComboBoxLEnabled
Memo1.Readonly
Memo1.ScrollBars
True
False
False
True
Vertical
Mamlakat nomini tanlash uchun ComboBoxl komponentasidan
foydalanilgan. Ro‘yxat loyihalashtirish jarayonida kiritilishi lozim.
Dastur matni:
Unit Unitl;
interface
-^5
- |Q| xl
C H iin n ih iii
C Tb-nilisll
M.iim1>ih.]l
Procedure ButtonlClick(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButtonlClick(Sender: TObject);
private
{ Private declarations } public
{ Public declarations } end;
Var
Forml: TForml;
implementation
{$R *.DFM}
procedure TForml.ButtonlClick(Sender: TObject) ;
Type
/ / tip medali
TKind = (GOLD,SILVER,BRONZE);
/ / zapis fayla
TMedal = record
country:string[20]; sport:string[20];
person:string[40]; kind:TKind;
end;
Var
f: file of TMedal;
rec: TMedal;
n: Integer;
st: string[80];
Begin
AssionFile(f, ’a:\medals.db’);
{$!-}
156
Memol.Clear; / / OMHCTHTb cnncoK nojia Memo
while not EOF(f) do begin
read(f, rec); / / npoMHTaTb 3anncb
if RadioButtonl.Checked or
(rec.country = ComboBoxl.Text) then begin
n := n + 1;
st := rec.person+ ', ' + rec.sport;
if RadioButtonl.Checked then
st := st + ', '+ rec.country; case rec.kind of
OOLD: st := st+ ', oltin';
SILVER:st := st+ ', kumush';
BRONZE:st := st+ ', bronza';
end;
Memol.Lines.Add(st); end;
end;
CloseFile(f); if n = 0 then
ShowMessage('Kerakli maiumot yo‘q.');
end;
Procedure TForml.RadioButton2Click(Sender: TObject);
Begin
Labell.Enabled := True;
ComboBoxl.Enabled := True;
ComboBoxl.SetFocus;
end;
Procedure TForml.RadioButtonlClick(Sender: TObject);
Begin
Labell.Enabled := False;
ComboBoxl.Enabled := False;
end;
end.
TForml.ButtonlClick protsedurasi faylni ochib yozuvlami ketma-
ket o‘qiydi. Yozuv Memol maydoniga, mamlakat nomi country maydoni
qiymatibilan mos kelsa yoki RadioButtonl tanlangan bolsa qo‘shiladi.
6.2. Dinamik tuzilmalar
Ko‘rsatkich deb qiymati boshqa o‘zgaruvchi yoki ma’lumotlar
tuzilmasi adresiga teng bolgan o‘zgaruvchiga aytiladi.
Ko‘rsatkichlar quyidagicha ta’riflanadi:
Nom: ATur;
Masalan:
pl: AInteger; r2: Areal;
Agar ko‘rsatkich hech narsaga tengligi ko‘rsatilmasa uning qiymati
NIL ga teng deyiladi.
Ko‘rsatkichga biror o‘zgaruvchi adresi qiymat sifatida berilsa @
adres olish operatoridan foydalaniladi. Masalan:
r := @n;
Ko‘rsatkichga boshqa ko‘rsatkich qiymatini berish mumkin, agar
ular bir turli bo‘lsa. Masalan:
p2 := pl;
Agar ko‘rsatkich i o‘zgaruvchiga ko‘rsatayotgan bo‘lsa.
rA: = 5;
instruksiya bajarilgandan so‘ng i qiymati 5 ga teng boladi.
|