Ajiniyoz nomidagi nukus davlat pedagogika instituti madaminov rasul urazbayevich
Download 1.63 Mb. Pdf ko'rish
|
- Bu sahifa navigatsiya:
- Foydalanish
- Function
- S: String; begin case
Library Cmplx;
Uses SysUtils, Classes; {$R*. RES} Type TComplex
51
Re, Im: Real; end; Function addC (x,y: Tcomplex): Tcomplex; stdcall; Begin Result.Im :
end; Function divC (x,y: Tcomplex): Tcomplex; stdcall; Var z: real; Begin z:
Result.Im:
52
Mulc index 3, divc index 4; begin end. Bu yerda stdcall bu DLL ga Delphi dan boshqa tillardan murojaat qilishga imkon beradi. Agar bibliotekaga faqat Delphi tilidagi dasturdan murojaat qilinsa, bu so’zning keragi yo’q. Bizning DLL dagi barcha funktsiyalar stdcall bilan berilishi bu API Windows32 ning yangi funktsiyalari bilan mos kelishini ta’minlaydi. Agar biz stdcall ni bermasak, kompilyator undan ko’ra samariloq bo’lgan register ni ishlatadi, lekin bu holda Delphi dan boshqa tillarda yozilgan dasturlardan DLL ga murojaat qila olmas edik.
ta’minlamoqchi bo’lsangiz, qismdasturlarni stdcall yoki safecall direktivasi bilan bering. Dll dan qism dasturlarni ishlatish uchun external xizmatchi so’zidan foydalaniladi. Masalan, Procedure MyProc; External ‘MyDl’; yoki Procedure MyProc; External ‘MyDll.dll’ index 2; yoki Procedure MyProc; external ‘MyDl.dll’Name ‘ExtName’; Shundan so’ng eksport qilinayotgan qismdastur Object Rascal dagi oddiy qism dasturga o’xshab chaqirilishi mumkin.
Statik yuklanish Quyidagi dasturda yuqorida keltirilgan Cmplx kutubxonasi ishlatiladi:
Re, Im: Real; End; 53
stdcall; External ’Cmplx.dll’; Function SubC(x,y: TComplex): TComplex; stdcall; External ’Cmplx.dll’; Function mulC(x,y: Tcomplex): TComplex; stdcall; External ’Cmplx.dll’; Function DivC (x,y: TComplex): TComplex; stdcall; External ‘Cmplx.dll’; Procedure TfmExample.bbRunClick(Sender: TObject); Var x, y, z: TComplex; procedure Output(Operation: Char); var S: String; begin case Operation of ‘+’: z := AddC(x,y); ' -' : z := SubC(x, y); ‘*’: z := MulC(x,y); ‘ / ’z := DivC(x,y); end;
S:=’(‘+FormatFloat(‘+0.0000; -0.0000’, x.re) + FormatFloat('+0.0000j;-0.0000j *, x.im) + ') ' + Operation+ . ' ('+FormatFloat (' +0.0000;-0,0000 ', y.re)+ . FormatFloat('+0.0000j;-0.0000j,y.im)+'=’ , + FormatFloat('+0.0000;- 0.0000’, z.re)+ FormatFloat('+0.0000j;-0.0000j’, x.im); mmOutput.Lines.Add(S);
54
begin x.re := Random; x.im := Random; y.re := Random; y.im := Random; , Output (‘ +’); Output (‘ -’); Output(' * '); Output(' / ');
DLL – qism dasturlarini chaqirishda yozuv kabi murakkab turdagi ma’lumotlarni uzatishga to’g’ri kelishi mumkin. Agar biror DLL ga ko’p murojaat qilinsa, murakkab tur e’lon qilingan interfeysli moduldan foydalanish qulaydir. Masalan:
TComplex=record Re, Im :Real; End; Function AddC (x,y:TComplex): TComplex; stdcall; External ‘Cmplx’ index1; function SubC(x,y:TComplex): TComplex; stdcall; External ‘Cmplx’ index2; Function MulC(x,y:TComplex): TComplex; stdcall; 55
Function DivC(x,y:TComplex): TComplex; stdcall; External ‘Cmplx’ INDEX4; Implementation end. Boshqa tilde yozilgan DLL protseduralariga murijaat qiilinganda ularning tashqi nomi delpi qoidasiga to’g’ri kelmasligi mumkin. Masalan, C++ tili identifikatorlarida «@» simvolidan foydalanishga ruxsat beradi. Bu holda Delphi qoidasiga mos nom berib «name» so’zidan so’ng asl nomini ko’rsatish kerak. Masalan: Function MyFunction: WordBool; stdcall; External ‘MyDLL’name-‘MyFuntion@12’ Dinamik bibliotekadan foydalanib kalkulyator yaratish. Formaning umumiy ko’rinishi quyidagicha bo’ladi (6-rasm):
6-rasm. Formaning umumiy ko’rinishi Oldin biz dinamik kutubxona yaratib olamiz. Buning uchun Delphi 7 dasturlash tilini ishga tushiramiz va File- New-Other ketma-ketlikni bajaramiz (7-rasm):
56
7-rasm.Dinamik kutubxona yaratish ketma-ketligi Quyidagi oyna hosil bo’ladi (8-rasm):
8-rasm.
Bu yerdan DLL Wizard bo’limini tanlaymiz va quyidagi ko’rinishdagi oyna hosil bo’ladi (9-rasm): 57
9-rasm Quyidagi kodlarni yozamiz va yangi papka ochib saqlaymiz (10-rasm):
10-rasm 58
Keyin Run menyusidan Run buyrug’ini tanlaymiz yoki klaviaturadan F9 klavishini bosamiz. File menyusidan CloseAll bandini tanlab barcha oynalarni yopamiz. Yangi forma ochamiz va unga 2 ta Edit, Label, ComboBox, Button komponentalarini quyidagidek ko’rinishda joylaymiz. Form1 ga sichqoncha tugmasini chertib function calc (a,b, index:integer):real; external 'dll.dll' kodini yozamiz. ComboBox ning Items xossasiga quyidagi so’zlarni yozamiz (11-rasm): Button1 ning OnClick hodisasiga label1.Caption:=Floattostr(calc(strtoint(edit1.text), strtoint(edit2.text),combobox1.ItemIndex)); ni yozib, dasturni ishga tushiramiz (12-rasm). Dastur ishga tushgach unda to’rtta arifmetik amalni bajarishimiz mumkin.
11-rasm
12-rasm. Dasturning umumiy
ko’rinishi |
ma'muriyatiga murojaat qiling