Solved

Only a doubt about creating component in run time

Posted on 2006-07-11
6
172 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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