• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • Last Modified:

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.
-----------------------------------------<
0
SupWang
Asked:
SupWang
1 Solution
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now