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
Solved

Declaring variables at runtim

Posted on 2002-07-04
12
226 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
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 25 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
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.

 
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: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 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