تعلم دلفي الأساسيات
-------------
unit Examples1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
Tfrm_examples = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Panel1: TPanel;
Button5: TButton;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
x: integer;
end;
var
frm_examples: Tfrm_examples;
implementation
{$R *.dfm}
uses Examples2;
procedure Tfrm_examples.Button1Click(Sender: TObject);
var
n: ShortInt;
begin
n := 127;
end;
procedure Tfrm_examples.Button2Click(Sender: TObject);
var
h, j, k: real;
begin
h := 10;
j := 9;
k := h / j;
ShowMessage(floattostr(k));
end;
procedure Tfrm_examples.Button3Click(Sender: TObject);
var
x, y, n, e, f: Variant;
begin
x := 'abc';
y := 123;
n := 124.33;
e := true;
f := y > 5 or e <> true;
end;
procedure Tfrm_examples.Button4Click(Sender: TObject);
var
a: boolean;
x, y: integer;
begin
if (Edit1.Text <> '') and (Edit2.Text <> '') then
begin
x := strtoint(Edit1.Text);
y := strtoint(Edit2.Text);
a := x > y;
if a then
ShowMessage('X > Y')
else
ShowMessage('Y > X');
end;
end;
procedure Tfrm_examples.Button5Click(Sender: TObject);
begin
if Edit3.Text <> '' then
x := strtoint(Edit3.Text);
frm_examples2.Show;
end;
end.
---------------
unit Examples2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
Tfrm_examples2 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Edit1: TEdit;
Button7: TButton;
Edit2: TEdit;
Panel1: TPanel;
Button8: TButton;
CheckBox1: TCheckBox;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Panel2: TPanel;
Button14: TButton;
Button15: TButton;
ComboBox1: TComboBox;
Panel3: TPanel;
Button16: TButton;
ListBox1: TListBox;
ComboBox2: TComboBox;
Button17: TButton;
ListBox2: TListBox;
Button18: TButton;
Panel4: TPanel;
Button19: TButton;
Memo1: TMemo;
Button20: TButton;
Memo2: TMemo;
Button21: TButton;
Memo3: TMemo;
Panel5: TPanel;
Button22: TButton;
ListBox3: TListBox;
Button23: TButton;
Memo4: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure Button20Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button22Click(Sender: TObject);
procedure Button23Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
frm_examples2: Tfrm_examples2;
implementation
{$R *.dfm}
uses Examples1;
const
y = 345.33;
Msg1 = 'أهلا بكم في لغة البرمجة دلفي';
Msg2 = 'لقد حدث خطأ عند إدخالك القيم';
Msg3 = 'تمت العملية بنجاح';
procedure Tfrm_examples2.Button10Click(Sender: TObject);
begin
if CheckBox1.Checked = true then
begin
Panel1.Color := clGreen;
CheckBox1.Caption := 'مفعّل';
end
else
begin
Panel1.Color := clRed;
CheckBox1.Caption := 'غير مفعّل';
end;
end;
procedure Tfrm_examples2.Button12Click(Sender: TObject);
begin
if CheckBox1.Checked then
if Panel1.Color = clRed then
begin
ShowMessage('تم التحقق من الشرط و سيتم تغيير اللون إلى الأخضر');
Panel1.Color := clGreen;
end;
end;
procedure Tfrm_examples2.Button13Click(Sender: TObject);
begin
if (CheckBox2.Checked = true) or (CheckBox3.Checked = true) then
Panel2.Color := clGreen
else
Panel2.Color := clRed
end;
procedure Tfrm_examples2.Button14Click(Sender: TObject);
begin
if not CheckBox2.Checked then
Panel2.Caption := 'تحقق الشرط'
else
Panel2.Caption := 'لم يتحقق الشرط';
end;
procedure Tfrm_examples2.Button15Click(Sender: TObject);
begin
{ if ComboBox1.ItemIndex=0 then
ShowMessage('أنت الآن في الشرط رقم 1');
if ComboBox1.ItemIndex=1 then
ShowMessage('أنت الآن في الشرط رقم 2');
if ComboBox1.ItemIndex=2 then
ShowMessage('أنت الآن في الشرط رقم 3');
if ComboBox1.ItemIndex=3 then
ShowMessage('أنت الآن في الشرط رقم 4');
if ComboBox1.ItemIndex=4 then
ShowMessage('أنت الآن في الشرط رقم 5'); }
case ComboBox1.ItemIndex of
0:
ShowMessage('أنت الآن في الشرط رقم 1');
1:
ShowMessage('أنت الآن في الشرط رقم 2');
2:
ShowMessage('أنت الآن في الشرط رقم 3');
3:
ShowMessage('أنت الآن في الشرط رقم 4');
4:
ShowMessage('أنت الآن في الشرط رقم 5');
end;
end;
procedure Tfrm_examples2.Button16Click(Sender: TObject);
var
i: integer;
begin
i := 1;
while i <= 10 do
begin
ListBox1.Items.Add('LAICHI HICHAM' + ' ' + inttostr(i));
i := i + 1;
end;
end;
procedure Tfrm_examples2.Button17Click(Sender: TObject);
var
i: integer;
begin
i := 0;
while i <= 10 do
begin
ComboBox2.Items.Text := ListBox1.Items.Text;
i := i + 1;
end;
end;
procedure Tfrm_examples2.Button18Click(Sender: TObject);
var
i: integer;
begin
i := 1;
while i < 20 do
begin
ListBox2.Items.Add(inttostr(i));
i := i + 2;
end;
end;
procedure Tfrm_examples2.Button19Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to 10 do
Memo1.Lines.Add('Counter N° ' + inttostr(i));
end;
procedure Tfrm_examples2.Button1Click(Sender: TObject);
begin
frm_examples.x := 7;
end;
procedure Tfrm_examples2.Button20Click(Sender: TObject);
var
i: char;
begin
for i := 'e' downto 'a' do
Memo2.Lines.Add('Character = ' + i);
end;
procedure Tfrm_examples2.Button22Click(Sender: TObject);
var
i: integer;
begin
i := 1;
repeat
ListBox3.Items.Add('Delphi; counter N° ' + inttostr(i));
i := i + 1;
until i > 10;
end;
procedure Tfrm_examples2.Button23Click(Sender: TObject);
var
counter: integer;
begin
counter := 1;
repeat
Memo4.Lines.Add(inttostr(counter));
counter := counter + 2;
until counter>20;
end;
procedure Tfrm_examples2.Button3Click(Sender: TObject);
begin
ShowMessage(Msg1);
end;
procedure Tfrm_examples2.Button4Click(Sender: TObject);
begin
ShowMessage(Msg2);
end;
procedure Tfrm_examples2.Button5Click(Sender: TObject);
begin
ShowMessage(Msg3);
end;
procedure Tfrm_examples2.Button6Click(Sender: TObject);
begin
if Edit1.Text = 'Hicham LAICHI' then
ShowMessage(Edit1.Text);
end;
procedure Tfrm_examples2.Button7Click(Sender: TObject);
begin
if Edit2.Text = 'Hicham' then
BEGIN
ShowMessage(Edit2.Text);
Panel1.Color := clGreen;
END;
end;
procedure Tfrm_examples2.Button8Click(Sender: TObject);
begin
if CheckBox1.Checked = true then
Panel1.Color := clGreen
else
Panel1.Color := clRed;
end;
procedure Tfrm_examples2.Button9Click(Sender: TObject);
begin
if CheckBox1.Checked = true then
begin
Panel1.Color := clGreen;
CheckBox1.Caption := 'مفعّل';
end
else
Panel1.Color := clRed;
end;
procedure Tfrm_examples2.FormCreate(Sender: TObject);
var
i: (hicham, ahmed, salim, sami, morad);
begin
for i := hicham to sami do
Memo3.Lines.Add('N° ' + inttostr(ord(i)));
end;
procedure Tfrm_examples2.FormShow(Sender: TObject);
begin
if frm_examples.x = 0 then
Color := clRed;
if frm_examples.x = 1 then
Color := clYellow;
if frm_examples.x = 2 then
Color := clGreen;
if frm_examples.x = 3 then
Color := clGray;
if frm_examples.x = 4 then
Color := clWhite;
end;
end.
--------
unit Examples3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
Tfrm_Examples3 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Edit1: TEdit;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
procedure AllMsg(x: integer); // Ctrl + Shift + c
function FormColor: string;
function MsgFunc: string;
function CalcFunc(x, y: Double): Double;
end;
var
frm_Examples3: Tfrm_Examples3;
implementation
{$R *.dfm}
{ Tfrm_Examples3 }
procedure Hello;
begin
ShowMessage('مرحبا بكم مع الإجراءات');
end;
procedure Tfrm_Examples3.AllMsg(x: integer);
begin
case x of
0:
ShowMessage('مرحبا بكم مع الإجراءات');
1:
ShowMessage('حدث خطأ أثناء إدخال القيم');
2:
ShowMessage('تمت العملية بنجاح');
3:
ShowMessage('أعد المحاولة لاحقا');
end;
end;
procedure Tfrm_Examples3.Button10Click(Sender: TObject);
begin
//ShowMessage( floattostr(CalcFunc(5,7)));
edit4.Text:= floattostr(CalcFunc(StrToFloat(edit2.Text),StrToFloat(edit3.Text)));
end;
procedure Tfrm_Examples3.Button1Click(Sender: TObject);
begin
Hello;
end;
procedure Tfrm_Examples3.Button2Click(Sender: TObject);
begin
Hello;
end;
procedure Tfrm_Examples3.Button3Click(Sender: TObject);
begin
Hello;
end;
procedure Tfrm_Examples3.Button4Click(Sender: TObject);
begin
Hello;
end;
procedure Tfrm_Examples3.Button5Click(Sender: TObject);
begin
Hello;
end;
procedure Tfrm_Examples3.Button6Click(Sender: TObject);
begin
if Edit1.Text <> '' then
AllMsg(strtoint(Edit1.Text));
end;
procedure Tfrm_Examples3.Button7Click(Sender: TObject);
begin
AllMsg(1);
end;
procedure Tfrm_Examples3.Button8Click(Sender: TObject);
begin
FormColor;
end;
procedure Tfrm_Examples3.Button9Click(Sender: TObject);
var
n: string;
begin
// ShowMessage(MsgFunc);
n := MsgFunc;
Caption := n;
end;
function Tfrm_Examples3.CalcFunc(x, y: Double): Double;
begin
result := x / y;
end;
function Tfrm_Examples3.FormColor: string;
begin
Color := clGray;
end;
function Tfrm_Examples3.MsgFunc: string;
begin
result := 'أهلا بكم مع الدوال';
end;
end.
Leave a Comment