Solved

Only a doubt about creating component in run time

Posted on 2006-07-11
6
165 Views
Last Modified: 2010-04-05
My doubt is that I am creating two components with the same name but in different procedures, can I have a problem with this?


See this code



Procedure OpenDB;

  procedure DeleteTMPDB(code: Integer);
  Var
    TQ : Tadoquery;
  Begin
    TQ : Tadoquery.Create(nil);
    ... etc
    Try
     Finally
      FreeAndNil(TQ)
    End
  End

Var
  TQ : Tadoquery;
Begin

  Begin
    TQ : Tadoquery.Create(nil);
    ... etc
    Try
       With TQ do
       Begin
          Sql.Add('Select * from table');
          Open;
       End;
       While TQ.Not Eof do
       Begin
          DeleteTMPDB(TQ.FieldByName('ID').AsInteger);
          TQ.Next;
       End
     Finally
      FreeAndNil(TQ)
    End
  End

End
0
Comment
Question by:hidrau
  • 4
  • 2
6 Comments
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

The variables are scoped differently, so there isn't an issue.

Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
Eg, an example to test scope of variables:

procedure TestScope;

  procedure TestInnerScope;
  var S:      String;
  begin
     ShowMessage(S);
  end;

var S:        String;
begin

  S:='Hello world';
  TestInnerScope;

end;
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
so, I could tell that they are connected by procedure, is it?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
Comment Utility
For further info, the Delphi help on the topic "Scope" reads as follows:

Naming conflicts

When one block encloses another, the former is called the outer block and the latter the inner block. If an identifier declared in an outer block is redeclared in an inner block, the inner declaration overrides the outer one and determines the meaning of the identifier for the duration of the inner block. For example, if you declare a variable called MaxValue in the interface section of a unit, and then declare another variable with the same name in a function declaration within that unit, any unqualified occurrences of MaxValue in the function block are governed by the second, local declaration. Similarly, a function declared within another function creates a new, inner scope in which identifiers used by the outer function can be redeclared locally.
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
>> so, I could tell that they are connected by procedure, is it?

Not sure I follow what you are asking... The only connection is in the fact that the DeleteTMPDB can only be called from within OpenDB, as DeleteTMPDB is a nested block. But the variable TQ  (because of the inner scope redeclaration) is 2 individual variables, where the usage depends on the scope (block level being executed)

Russell
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
Yeah, TQ are two different variables and none of them affects each other. That's all that I would like to know. :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now