Functions and procedures in DELPHI 7

need ur help -  
 montecristo -
Hello everyone,
I am currently learning Delphi using an online guide which can be found here: https://fbeaulieu.developpez.com/guide/

However, I encountered a problem with the functions:
I followed step by step what was described in the guide (creating a project, declaring the function, etc.) but the compiler found many errors, notably it didn't recognize the variable "result" even though it is supposedly predefined!! (That's what I understood) with functions! Is it because of the version of Delphi?

Looking forward to your responses!!
Configuration: Windows XP Firefox 1.5.0.12

3 answers

  1. montecristo
     
    The problem comes from the fact that you do not implement your function in your unit calculation
    your function
    unit calculation;

    interface
    {this part is good}
    function AireDisque(Rayon: Single): Single;

    implementation
    {here you need to implement your method like this}
    //start of method
    function AireDisque(Rayon: Single): Single;

    begin
    Result := PI * Rayon * Rayon;
    end; //end of method

    end.
    once you are sure of your code, save the unit calculation
    and add it to the uses clause
    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, calcul;

    normally you should see it appear
    I write my own procedures or functions in a separate unit first on a form to test, then I copy them into my file
    one trick, look at how Delphi constructs these procedures with components, it will save you time
    for example your button, look at the events assigned to it
    how they declare them and where the methods are located
    2
  2. amira
     
    Hello,
    I am working on an arithmetic operation but I have a problem with the result which is for example 6.66666........ I know there is a predefined function in Delphi, please I need this function
    thank you.
    1
  3. need ur help
     
    Hello, it's me again!
    Here is exactly what I did in my Delphi
    I created a project (premierEssai.dpr) containing a unit 'principale.pas' with its form (forme1); and a calculation unit (without a form)

    Here is the body of principale:
    unit principale;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,calcul;

    type
    TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
    aire : single;
    begin
    ShowMessage ('Bravo! Good answer :)');
    aire := AireDisque(3.2);
    end;

    end.

    And the body of the calculation unit

    unit calcul;

    interface
    function AireDisque(Rayon: Single): Single;

    implementation
    function AireDisque(Rayon: Single): Single;

    begin
    Result := PI * Rayon * Rayon;
    end;

    end.

    And after compilation here are the errors that the compiler displays:
    [Error] calcul.pas(7): Declaration expected but identifier 'AireDisque' found
    [Error] calcul.pas(10): Undeclared identifier: 'Result'
    [Error] calcul.pas(10): Undeclared identifier: 'Rayon'
    [Error] calcul.pas(11): '.' expected but ';' found
    [Error] calcul.pas(4): Unsatisfied forward or external declaration: 'AireDisque'
    [Fatal Error] principale.pas(8): Could not compile used unit 'calcul.pas'

    Please help me understand better
    and thank you in advance.
    0