?
Solved

assign variable name at runtime

Posted on 2002-03-09
7
Medium Priority
?
929 Views
Last Modified: 2012-05-05
I'm creating a TDatabase component at runtime.

Example:
var
  DataBase1: TDatabase;
begin
  Database1:= TDataBase.Create(nil);
End;

How do I declare a variable name at runtime.  I don't
want my variable name to be DataBase1, instead I want
to assign a name to it at runtime.  How can I do this?

Thanks  
0
Comment
Question by:brettawv
[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
7 Comments
 
LVL 2

Expert Comment

by:DelphiArchitect
ID: 6853327
I'm not following.  You can name DataBase1 anything you like such as MyDB:

var
  MyDB:TDatabase;
begin
  MyDB := TDatabase.Create(nil);
  try
    ...
  finally
    MyDB.Free;
  end;
end;

The variable name, itself, has no existance at runtime.  Are you by chance talking about the Database name that you need to assign to TTables, TQuerys, etc. to access this database?  If so you simply do:

  MyDB.DatabaseName := 'name';

Where name can be any valid database name (not certain if these can have spaces, etc).  Or you could do:

  MyDB.DatabaseName := 'temp_' + IntToStr(Random(65535));

Hope this helps.

Delphi Architect
James Higgins
0
 

Author Comment

by:brettawv
ID: 6853437
I'm writing a web app that accesses an AS400.  I have a component which allows me hooks into the AS400.  I use a database component and the databasename of the component is the alias used to give me access to the AS400.  When two people try to access the database at the same time the first person gets their response but the second person gets an error saying that the databasename is in use.
As long as the first persons request is completed before the second person submits their request, everything works fine.  What I'm trying to do is create another instance of the database that will run if the first one is not yet free.  I want to assign the sessionid as the variable name for the database before I create it.  This way I can keep track of which one is still active and which one is ready to be freed.  Is it possible to do this?
0
 
LVL 2

Accepted Solution

by:
craig_capel earned 400 total points
ID: 6853947
Var
  UsersConnected: Integer;

Example:
 var
   DataBase1: Array[1..10] of TDatabase;
   begin
    Inc(UsersConnected);
    Database1:= TDataBase[UsersConnected].Create(nil);
  End;


so you can create multiple instances of it as of and when you need it.
0
Independent Software Vendors: 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 2

Expert Comment

by:craig_capel
ID: 6853953
Database1[UsersConnected]:= TDataBase.Create(nil);

oops sorry change that line for this. :)
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6854295
You cannot change the name of any variable at runtime.
0
 
LVL 17

Expert Comment

by:geobul
ID: 6854356
Hi,
There are two basic types of web apps that can be created with Delphi: CGI (exe) and ISAPI/NSAPI (dll). They both support internally what you are trying to do. Many copies of a CGI app are executed simultaneously as many times as there are requests received. On the other hand ISAPI is loaded once in memory and creates its copies on request or uses already created copies that are currently not in use.

So, make your app CGI or ISAPI and there won't be such a problem.

Regards, Geo
0
 

Author Comment

by:brettawv
ID: 6854704
Thanks, This will help me accomplish what I was trying to do.  I appreciate the help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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…
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

762 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