




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























Partager l’info c’est progresser ensemble
اتأساسيـــــ • دمــــواجهة المستخ • داثــــاألح • اتـــة البيانـــمعالج • البيانـــاتدـــقواع •
الفهــــــــرس
مقدمة في البرمجة ودلفي. 1 البرمجة؟ما هي. 1 - 1
لماذا تتعلم دلفي؟. 2 - 1
أساسيات دلفي: المتغيرات وأنواع البيانات والعبارات الشرطية والحلقات. 3 - 1
المتغيرات. 1 - 3 - 1
var age: Integer ; begin age := 30 ; end.
WriteLn('myString: ', myString); WriteLn('myBool: ', myBool); WriteLn('myChar: ', myChar); // Display array values WriteLn('myArray[0]: ', myArray[ 0 ]); WriteLn('myArray[1]: ', myArray[ 1 ]); WriteLn('myArray[2]: ', myArray[ 2 ]); // Display record values WriteLn('myRecord.name: ', myRecord.name); WriteLn('myRecord.age: ', myRecord.age); WriteLn('myRecord.isMale: ', myRecord.isMale); // Wait for user input ReadLn; end.
العبارات الشرطية. 1 - 1 - 1
Exemple 3 : Instruction IF program IfExample; {$APPTYPE CONSOLE} var myInt: Integer ; begin Write('Enter a number: '); ReadLn(myInt); if myInt > 0 then WriteLn('The number is positive.') else if myInt = 0 then WriteLn('The number is zero.') else WriteLn('The number is negative.'); ReadLn; end.
program CaseExample; {$APPTYPE CONSOLE} var myChar: Char; begin Write('Enter a letter: '); ReadLn(myChar); case myChar of 'A', 'E', 'I', 'O', 'U': WriteLn('The letter is a vowel.'); 'Y': WriteLn('The letter is sometimes a vowel.'); else WriteLn('The letter is a consonant.'); end; ReadLn; end.
الحلقات. 3 - 3 - 1
"بينما" حلقــة. أ
Exemple 7 : Boucle FOR program ForExample; {$APPTYPE CONSOLE} var i: Integer; begin for i := 0 to 9 do WriteLn(i); ReadLn; end.
واجهة المستخدم. 2
)GUIsمقدمة إلى واجهات المستخدم الرسومية (. 1 - 2
var Form1: TForm1; clients: array of TClient; currentClientIndex: integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin // Initialiser la liste des clients SetLength(clients, 0 ); currentClientIndex := - 1 ; end; procedure TForm1.btnAjouterClick(Sender: TObject); var newClient: TClient; begin // Créer un nouveau client à partir des données saisies dans le formulaire newClient.nom := edtNom.Text; newClient.prenom := edtPrenom.Text; newClient.age := StrToIntDef(edtAge.Text, 0 ); // Ajouter le nouveau client à la liste des clients SetLength(clients, Length(clients) + 1 ); clients[High(clients)] := newClient; // Sélectionner le nouveau client dans la liste currentClientIndex := High(clients); // Mettre à jour l'affichage AfficherClient(); end; procedure TForm1.btnSupprimerClick(Sender: TObject); begin if currentClientIndex >= 0 then begin // Supprimer le client sélectionné de la liste for var i := currentClientIndex to High(clients) - 1 do clients[i] := clients[i + 1 ]; SetLength(clients, Length(clients) - 1 ); // Sélectionner le client précédent ou suivant dans la liste if currentClientIndex >= Length(clients) then currentClientIndex := Length(clients) - 1 ; if currentClientIndex >= 0 then AfficherClient() else EffacerClient(); end; end; procedure TForm1.AfficherClient();
begin // Afficher les données du client sélectionné dans les champs du formulaire edtNom.Text := clients[currentClientIndex].nom; edtPrenom.Text := clients[currentClientIndex].prenom; edtAge.Text := IntToStr(clients[currentClientIndex].age); end; procedure TForm1.EffacerClient(); begin // Effacer les champs du formulaire edtNom.Text := ''; edtPrenom.Text := ''; edtAge.Text := ''; end; إلخ.)نص،مربعاتأزرار،إضافة مكونات (. 3 - 2
Exemple 11 : Utilisation des composants procedure TForm1.FormCreate(Sender: TObject); var myButton: TButton; myLabel: TLabel; myEdit: TEdit; begin // Créer un bouton myButton := TButton.Create(Self); myButton.Parent := Self; myButton.Caption := 'Cliquez-moi !'; myButton.Left := 50 ; myButton.Top := 50 ; // Créer une étiquette myLabel := TLabel.Create(Self); myLabel.Parent := Self;
احداث. 3 الحدث؟ما هو. 1 - 3
كيف يتم استخدام األحداث في دلفي؟. 2 - 3
Exemple 12 : Principe d’utilisation d’un évènement procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage('Le bouton a été cliqué !'); end; مل مع األحداث (على سبيل المثال، كيفية تنفيذ إجراء عندمااعتأمثلة عملية لل. 3 - 3 ينقر المستخدم على زر)
Exemple 13 : Formulaire avec gestion d’évènement procedure TForm1.btnValiderClick(Sender: TObject); var nom, prenom: string; age: Integer; begin nom := txtNom.Text; prenom := txtPrenom.Text; age := StrToIntDef(txtAge.Text, 0 ); if (nom <> '') and (prenom <> '') and (age > 0 ) then begin ShowMessage('Bonjour ' + prenom + ' ' + nom + ', vous avez ' + IntToStr(age) + ' ans.'); end else begin ShowMessage('Veuillez remplir tous les champs avec des valeurs valides.'); end; end;
Person.Name := 'John Doe'; Person.Age := 42; Person.Email := '[email protected]';
Exemple 14 : Enregistrement avec méthodes type TMyData = record Value: Integer; function Add(aValue: Integer): Integer; procedure Print; end; function TMyData.Add(aValue: Integer): Integer; begin Result := Value + aValue; end; procedure TMyData.Print; begin Writeln(Value); end;
-------------------------- Utilisation --------------------------- var MyData: TMyData; begin MyData.Value := 10 ; MyData.Print; // affiche 10 à l'écran MyData.Value := MyData.Add( 5 ); MyData.Print; // affiche 15 à l'écran end;
Objectكائن. 3 - 4
Exemple 15 : Objet avec méthodes type TMyObject = class private FValue: Integer; public constructor Create(AValue: Integer); function GetValue: Integer; procedure SetValue(AValue: Integer); procedure Add(AValue: Integer); end; constructor TMyObject.Create(AValue: Integer); begin FValue := AValue; end; function TMyObject.GetValue: Integer; begin Result := FValue; end; procedure TMyObject.SetValue(AValue: Integer); begin FValue := AValue; end; procedure TMyObject.Add(AValue: Integer); begin FValue := FValue + AValue; end;