Solved

Only a doubt about creating component in run time

Posted on 2006-07-11
6
168 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

15 Experts available now in Live!

Get 1:1 Help Now