What's the difference with this code?

Hi all,
What's the difference with the following code?

Thank you very much.

Regards, SupWang


----------------------------------------->
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
  function Calculate(FirstValue, SecondValue: Integer): Integer;    //I declare this in here
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

function TForm2.Calculate(FirstValue, SecondValue: Integer): Integer;
begin
  Result := FirstValue*SecondValue;
end;

end.
-----------------------------------------<




----------------------------------------->
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  function Calculate(FirstValue, SecondValue: Integer): Integer;  //I declare this in here
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

function TForm2.Calculate(FirstValue, SecondValue: Integer): Integer;
begin
  Result := FirstValue*SecondValue;
end;

end.
-----------------------------------------<
LVL 2
SupWangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
In the first sample you have declared function Calculate in an area where the IDE is working in to place your event handlers etc. Never change this area or you may loose your DFM or code! Always place your stuff into the normal sections (protected, private etc.) and leave the section where the IDE works alone.

Ciao, Mike
0
SupWangAuthor Commented:
Hi Mike,
sure? Do you means I should use the second way?
But in my some project, I also have use the first way to declaring the procedure/function,
Not have any problem.

sorry, I reject you answer because i want more people see this question, and if you are right,
i will give the points to you and also will give 15 points to another people.

Regards, SupWang
0
LischkeCommented:
Okay, your decision. You won't attract many people to comment here for a 15 points question, though...

Ciao, Mike
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

BlaiseCommented:
From doing a little experimentation, it seems that in
---
type
     TForm2 = class(TForm)

        AREA A

      private
           { Private declarations }
      public
           { Public declarations }
       end;

---
In area A, the items there (usually components embedded in the TForm)
are visible as though they were declared in the PUBLIC section, (i.e.
another outside component can reference FORM2.BUTTON1).

I agree that in application design you should declare items in the PUBLIC
section if you plan to reference them from another object, such as another form.  If the components/variables you declare are only referenced within the code of the form itself, you should declare them as private.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kretzschmarCommented:
hi supwang,

found in my delphi-helpfile (d3) a description
(sorry in my local language, therefore i can't it paste here)
look at the keywords (translated into english):
-visibilty of components
-published components
-public components

meikl ;-)
0
SupWangAuthor Commented:
Hi all,
Thanks.
What's the difference with the following code?

--------------------------------------->
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

function Calculate(FirstValue, SecondValue: Integer): Integer;
begin
  Result := FirstValue*SecondValue;
end;

end.
---------------------------------------<

--------------------------------------->
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    function Calculate(FirstValue, SecondValue: Integer): Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

function TForm1.Calculate(FirstValue, SecondValue: Integer): Integer;
begin
  Result := FirstValue*SecondValue;
end;

end.
---------------------------------------<


Hi meikl,
Have a local language delphi? That's great. But delphi not have a chinese version. :-(

0
SupWangAuthor Commented:
Not have comments?

anyway. Thanks.

meikl, please look at this and get the points.
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10244204 

Mike, Please look at this and get the points.
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10244207 f

Thanks, SupWang
0
LischkeCommented:
Got it, thank you...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.