Solved

Declaring variables at runtim

Posted on 2002-07-04
12
227 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 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
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

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…

730 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