Solved

C++ Builder:   open file by command line and inputBox

Posted on 2001-08-02
9
688 Views
Last Modified: 2012-06-27

DBTable->DatabaseName=AnsiString InputBox"("File routine","routine","C:\");
DBTable->TableName=InputBox"("Filename","filename","filename");
DBTable->Open();

________________________
Above code dose not work. Below code work, but the filename can not be modified during running. How to modify above code?
________________________


DBTable->DatabaseName="c:\\temp\\temp2";
DBTable->TableName="temp.db";
DBTable->Open();
0
Comment
Question by:Johncili
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 50 total points
ID: 6346466
>>Above code dose not work.
Exactly what does not work.  Please give details.

Try the following for the lower code:

char data1[] = "c:\\temp\\temp2";
char data2[] = "temp.db";
DBTable->DatabaseName=data1;
DBTable->TableName=data2;
0
 
LVL 22

Expert Comment

by:nietod
ID: 6346477
DBTable->DatabaseName=InputBox"("File routine","routine","C:\");

should be

DBTable->DatabaseName=AnsiString InputBox"("File routine","routine","C:\\");

the \ character is an escape character and it is treated specially in a string literal.  If you wish to include a single \ in a string, you must actually write two \s.  this does not cause two \s to be stored, only one.  

Also note that there was an extra "AnsiString" stuck in there.
0
 

Author Comment

by:Johncili
ID: 6346516
Still it did not work.

DBTable->DatabaseName=AnsiString InputBox("File routine","routine","C:\\");

I just want to pop-up an input box, and the filename can be input.

Any one know?
0
 
LVL 30

Expert Comment

by:Axter
ID: 6346527
You still AnsiString after the equal sign.

See nietod's comment.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 6346544
its that extra "AnsiString" in the middle of the line.

I'm not sure why you think you need it.  it is like doing

int x = 5;
int y = int x; // ERROR

You don't want that "int" thrown in before the "x" on the 2nd line.

On the 2nd line the compiler knows that x is an int.

In your code, the compilers knows that InputBox() returns an AnsiString..
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6347406
better use
..AnsiString InputBox("File routine","routine","");

0
 

Expert Comment

by:sant3000
ID: 6347881
hello, the real problem is what u can't modify DatabaseName in runtime...so, u have only one way to avoid this problem.. delete DBTable object and create new one with modified DatabaseName
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6349449
O, of course you can't change name during Databas is opened
Yur must close every
connection to the database before change the path. The code will look
something like : (example change ODBC name)

LoginDatabase->Close();

ODBC ODBCChange;
/*
 Don't forget that the name ODBC_NAME must be the same as under wich you
 created it
 */
 ODBCChange.ChangePath("ODBC_NAME","c:\\database.mdb");
 
 LoginDatabase->LoginPrompt=false;
 LoginDatabase->DatabaseName = "ODBC_NAME";
 LoginDatabase->KeepConnection = true;
 LoginDatabase->Open();



0
 
LVL 30

Expert Comment

by:Axter
ID: 6360540
Johncili,
A C grade???
Ooch, that hurts...

I notice that you have the following grading record:
C C C B

Most questions should be given an 'A' grade, unless the expert fails to answer any additional questions.

If you continue to grade answers with C's and B's, experts will not want to help you in the future.

Experts do not get paid for helping you.  Please show your graditue by giving them the grade they deserve.

Thank you for the points, but in the future, please be gentel with my grading record.

Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now