| |
òåìí
äãìôé
ùéòåø
4: äáä ð÷åãã!
îîéø ùòø äçìéôéï äàéøåôàé ùìðå òãééï ìà
òåùä ùåí ãáø ùéîåùé. áùéòåø æä ðåñéó ÷öú ÷åã
àîéúé ìîáöòé äîàåøò (event handler).
äáä ð÷åãã!
áùéòåø 3 ùîðå
÷öú ÷åã æîðé áîáöò äîàåøò ùìEuroButton àáì
îä îáöò îàåøò æä áàîú òåùä?
àðçðå ùåîøéí àú ëì äòøëéí åäè÷ñèéí
äæîðééí áîùúðéí Euro,
F1, S1,
å-S2
. öøéê
ìäöäéø òì îùúðéí: æä îöáéò òì ëê ùäí îùúðéí (ãøê
äîéìä äùîåøä var)
åëï âí ñåâí áà àçøé ùîí. æä îáåöò
ìôðé äîéìä äùîåøäbegin
áøåèéðä.
áéðúééí àì úãàâ ìëì äñåâéí äùåðéí ùì
äîùúðéí. áäîùê ðçæåø ìôøè æä.
1.
áåà
ð÷åãã! äúçì àú ãìôé åôúç àú äôøåéé÷èeuroen01.dpr ãøê
úôøéè ä- File
åäàåôöéä
…
Open
Project
2.
äçìó
àú äè÷ñè äðéñéåðé ùì îáöò äîàåøò ùì EuroButton`s
OnClick
áè÷ñè äçãù:
procedure TForm1.EuroButtonClick(Sender: TObject);
var
Euro, Fr: real;
S1, S2: string;
begin
CurrLabel.Caption := 'Euro';
Euro := StrToFloat(InputEdit.Text);
Fr := Euro * 40.3399;
S1 := FormatFloat('0.00', Euro);
S2 := FormatFloat('0.00', Fr);
EuroLabel.Caption := S1;
BEFLabel.Caption := S2;
end; |
3.
÷îôì
åáãå÷: æä òåáã!…
ìôçåú, àí ìà áöòú àó ùâéàú äãôñä :-).
4.
áåà
ðòöåø àú äàôìé÷öéä åðîùéê ìúëðú.
BEFButtonöøéê
ìòùåú àú ääéôê î- EuroButton:
äè÷ñè "BEF"
çééá ìäåôéò á- CurrLabel
åäòøê á-Euro öøéê
ìäéåú îåîø ì- BEF
(îçåì÷ á- 40.3399) ëì äùàø ëîòè æää ìîáöò äîàåøò
ùëúáðå òáåø EuroButton.
á- BEFButton,
áçø áîàåøò (eventOnClick
á-
(Object
Inspector
åìçõ ìçéöä ëôåìä òì äùãä äìáï ìéãå. ãìôé
ðåúðú ùí ìîáöò äîàåøò äçãù:BEFButtonClick.
á- Editor,
äùìí àú îáöò äîàåøò ìäìï:
procedure TForm1.BEFButtonClick(Sender: TObject);
var
Euro, Fr: real;
S1, S2: string;
begin
CurrLabel.Caption := 'BEF';
Fr := StrToFloat(InputEdit.Text);
Euro := Fr / 40.3399;
S1 := FormatFloat('0.00', Euro);
S2 := FormatFloat('0.00', Fr);
EuroLabel.Caption := S1;
BEFLabel.Caption := S2;
end; |
5.
÷îôì
åáãå÷. àéçåìé!
6.
ùîåø àú äôøåé÷è
(Save all).
[ìøàù
äòîåã]
äåñôú äòøåú
äåñôú äòøåú ì÷åã äî÷åø äéà ôòåìä áòìú
çùéáåú òìéåðä. ëøâò àúä ëåúá àú ä÷åã, àúä
éåãò áãéå÷ ìîä äúëååðú. àáì áòåã ùáåò, çåãù,
ùðä? ëï, ùîòúé ùîúëðúéí àîéúééí ìà îôøùéí àú
ä÷åã ùìäí…
âøåò éåúø àðùéí ìà ÷åøàéí àú äåøàåú
äùéîåù, ëéååï ùáñåôå ùì ãáø àúä éëåì ì÷øåà
àåúï àí äëìá ìà ìòñ àåúï J
àúä éëåì ìäåñéó äòøåú ìéçéãú (unit)
äãìôé áëîä ãøëéí.
// Any text between a double-slash and the end of the line is comments
// Look at this:
S1 := Edit1.Text // the text of Edit1 is assigned to S1
{ Text between a left brace and a right brace is a comment.}
{ Comments between braces can extend over several lines.
This comments block ends at the end of this line. }
(* The combination of rounded brackets and asterix may be used
instead of the brackets { }. This is useful if you want to
'nest' comments, which is impossible if you use only ONE
type of comments delimiters.
I never use this notation for comments. I use it to disable
code temporarily during tests, as in the following example: *)
(*
{ This code seems to be faulty. Let's disable it and see if
things get better that way. }
Label1.Text := Edit1.Text;
*) |
á- Editor,
äòøåú îåôéòåú áàåôï ùåðä: àåúéåú ëçåìåú
ðèåéåú. áãôéí àìå ìà àøàä äòøåú áàåúéåú
ðèåéåú, æä éäéä ÷öú îåâæí åìà ðåç ì÷øéàä.
ëîå ëï àìîðèéí àçøéí éîñøå áöåøä îéåçãú:
îéìéí ùîåøåú éåãâùå, è÷ñè )îçøåæú
áùôú ãìôé) éåôéò áöáò ëçåì, îñôøéí áöáò àãåí,
åëê äìàä. ä÷áéòä ùì æä äéà áúôøéè Tools
=> Environment
Options =>
çåöõ Color.
áúôøéè Environment
Options<=Tools=>çåöõ
.Color
äåñôúé ÷öú äòøåú ìéçéãä eruoform.pas (unit).
äñúëì òì ä÷åã äáà åäåñó äòøåú ìâøñà ùìê.
unit euroform;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
InputEdit: TEdit;
CurrLabel: TLabel;
Label2: TLabel;
EuroLabel: TLabel;
BEFLabel: TLabel;
Label5: TLabel;
Label6: TLabel;
EuroButton: TButton;
BEFButton: TButton;
procedure EuroButtonClick(Sender: TObject);
procedure BEFButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ Event handler for the OnClick event of EuroButton:
conversion from Euro to BEF.
Shows the name of the starting currency, converts the text
of the Edit-box to Belgian francs, shows the results. }
procedure TForm1.EuroButtonClick(Sender: TObject);
var
Euro, Fr: real;
S1, S2: string;
begin
// Show the name of the starting currency
CurrLabel.Caption := 'Euro';
// Convert the text of the EDIT to a numerical value
Euro := StrToFloat(InputEdit.Text);
// Convert from Euro to BEF
Fr := Euro * 40.3399;
{ Convert the floating point numbers to string-format.
'0.00' is the 'Format String', meaning:
'format the result with 2 decimal digits to the right
of the decimal separator' }
S1 := FormatFloat('0.00', Euro);
S2 := FormatFloat('0.00', Fr);
// Put the strings in the CAPTION of the LABELs
EuroLabel.Caption := S1;
BEFLabel.Caption := S2;
end;
{ Event handler for the Onclick event of BEFButton:
conversion from BEF to Euro.
Shows the name of the starting currency, converts the text
of the Edit-box to Euro, shows the results. }
procedure TForm1.BEFButtonClick(Sender: TObject);
var
Euro, Fr: real;
S1, S2: string;
begin
// Show the name of the starting currency
MuntLabel.Caption := 'BEF';
// Convert the text of the EDIT to a numerical value
Fr := StrToFloat(InputEdit.Text);
// Convert from BEF to Euro
Euro := Fr / 40.3399;
{ Convert the floating point numbers to string-format.
'0.00' is the 'Format String', meaning:
'format the result with 2 decimal digits to the right
of the decimal separator' }
S1 := FormatFloat('0.00', Euro);
S2 := FormatFloat('0.00', Fr);
// Put the strings in the CAPTION of the LABELs
EuroLabel.Caption := S1;
BEFLabel.Caption := S2;
end;
end. |
ìäúøàåú áùéòåø 5!
[ìøàù
äòîåã]
Copyright (C) 2000 Guido Festraets
Webmaster of the DelphiLand site: http://www.festra.com
|
|
|