Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't create instance of TStrings

Posted on 1999-07-16
10
Medium Priority
?
415 Views
Last Modified: 2010-04-06
This is probably a pretty dumb question but I'm having a serious problem trying to create an instance of TStrings for use with the GetKeyNames method in TRegistry.  The compiler gives me a warning about creating an instance with abstract methods...I'm sure I've used TStrings before without a problem.

Here's my code:
var
   myStrings:TStrings;
   myReg:TRegistry;
begin
   myStrings:=TStrings.Create;{error happens here}
   myReg:=TRegistry.Create;
   myReg.GetKeyNames(myStrings);
   myStrings.free {error happens here}
end;

what am I doing wrong??
0
Comment
Question by:jnickle
[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
  • 6
  • 4
10 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 1389233
Replace Tstring with TStringList
0
 

Author Comment

by:jnickle
ID: 1389234
Your lucky to get this one...I just posted it and not 2 minutes later I figured it out and was about to delete the question...do you have an alarm setup up with EE for easy questions that come in?? or right time right place?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1389235
"TStrings is an abstract base class for objects that represent a list of strings."

That means that TStrings does not work on its own. So use TStringList. This is what you need.

Regards,

Epsylon.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:Epsylon
ID: 1389236
I just passed by  :o)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1389237
You know, when I once started programming with Delphi I have been struggling with same thing  :o)

I think this was the fastest answered question ever on E-E

Thanks for the points!

Cheers,

Epsylon.
0
 

Author Comment

by:jnickle
ID: 1389238
How bout I make you earn it...is it possible to conditionally run an application?  I have a login screen that I want to cancel the app from running if not successfull.  I was thinking of using a variable in the projects source and then setting it somehow..the how's what I can't figure out...how do I expose a property to do this?  When I call application.terminate it still executes code and gives me errors because I've already released the form.  what would you suggest?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1389239
Hi,

this is easy! Create an additional form (Form2) where the use can type the login name and password. Call this form in your mainform's OnActivate event:

procedure TForm1.FormActivate(Sender: TObject);
begin
  if Form2.ShowModal = mrCancel then
    Close;  // Application.Terminate should work to
end;


In form2's unit set 'ModalResult' to mrOk when the password is ok, or mrCancel when not.

Eps.
0
 

Author Comment

by:jnickle
ID: 1389240
Ok thanks...I was doing it in the OnCreate Event...but wouldn't that be called everytime the form is activated or would that not be a problem if there's only one form within the application(besides the login)
0
 

Author Comment

by:jnickle
ID: 1389241
Ok thanks...I was doing it in the OnCreate Event...but wouldn't that be called everytime the form is activated or would that not be a problem if there's only one form within the application(besides the login)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1389242
You could use this to prevent that:

procedure TForm1.FormActivate(Sender: TObject);
begin
  if Form2.ShowModal = mrCancel then
    Close
  else
    OnActivate := nil;
end;



0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

688 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