Solved

Only a doubt about creating component in run time

Posted on 2006-07-11
6
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17081695

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

Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17081747
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
ID: 17081789
so, I could tell that they are connected by procedure, is it?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
ID: 17081810
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
ID: 17081854
>> 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
ID: 17081984
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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