Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

assign variable name at runtime

Posted on 2002-03-09
7
Medium Priority
?
931 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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!

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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

597 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