Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Only a doubt about creating component in run time

Posted on 2006-07-11
6
Medium Priority
?
188 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

670 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