?
Solved

Declaring variables at runtim

Posted on 2002-07-04
12
Medium Priority
?
230 Views
Last Modified: 2010-04-04
Is it possible to declare a variable at runtime ?

I want something like this :

procedure TForm1.SomeProc(Validated : Boolean);
begin
   if Validated then
   begin
      strList : TStringList;
      strList.Create(nil);
      // Do some stuff...
      strList.Free;
   end;
end;
0
Comment
Question by:sruel
[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
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 100 total points
ID: 7129870
This is completely impossible for a compiled language.
Only a interpreted language can do that.

The above example does not need it.
strList is only a pointer. The object it points to IS created at runtime.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7129875
not possible,
except you've an inbuild-compiler

but why you want this,
why not easy

procedure TForm1.SomeProc(Validated : Boolean);
var strList : TStringList;
begin
  if Validated then
  begin
     strList.Create(nil);
     // Do some stuff...
     strList.Free;
  end;
end;

as you have to code the logic also

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7129878
hi robert :-))
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:lucika
ID: 7129881
procedure TForm1.SomeProc(Validated : Boolean);
begin
  if Validated then
  begin
     with TStringList.Create(nil) do
     begin
       // Do some stuff...
       Free;
     end;
  end;
end;
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 7129905
kretschmar, lucika: TStringList.Create not TStringList.Create(nil). TStringList is no component.
Shame on you ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7129917
>Shame on you ;-)
just copied

;-)
0
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 7130091
Shame on What?
1. inthe: 504306 pts  
2. Madshi: 471558 pts  
3. kretzschmar: 422246 pts  

Best Regards.
Marcos.

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7130259
atleast, robert is right,
the creator of the tstringlist has no parameter,
but i've just copied the given code

shame on me :-))

meikl ;-)
0
 

Author Comment

by:sruel
ID: 7130511
So, I should give the points to wich one of you ?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7130555
give it robert,
he was the first who pointed out,
that this is impossible

meikl ;-)
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 7130640
if you didn't know how many integers (say) you wanted then during run time a dynamic array of integers would suit nicely!

:-)
0
 

Author Comment

by:sruel
ID: 7131009
Ok, thanks to all of you folks !
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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…
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 video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

770 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