Solved

Fail to declare AnsiString

Posted on 2000-03-30
11
338 Views
Last Modified: 2008-02-20
I use Borland C++Builder 3 and I want to use the Length function. Thus, I added two lines at the beginner of the source file:

#include <vcl/dstring.h>
#include <stdio.h>

However, when I press Run, a sysdefs.h windows opened and I receive a error message:

[C++Error] sysdefs.h(427):,expected.


What should I do?

Thank you very much.
0
Comment
Question by:saikit
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2669014
The error message is saying there is a syntax error.  it is expecting a coma.  You probably left out a coma.

We can't tell you anymore than that.  We don't have the code.  
0
 

Author Comment

by:saikit
ID: 2671416
I haven't put any code in the source, only include two headers and they are provided by the C++Builder.

Should I need to reinstall it or do some config in somewhere?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2671659
>> I haven't put any code in the source
ANY?  like the only thing in the source code is the two include lines?  If so that is a problem.  You will need to more in our program.  At the very least you need a main() (or WinMain()) procedure.  If that's not what you meant, sorry to insult you.
0
 

Author Comment

by:saikit
ID: 2671779
My program is just as below:

#include <vcl/dstring.h>
#include <stdio.h>

void main()
{
printf("Hello World");
}


After pressed Run, the sysdefs.h was open and stop at a line:

typedef SmallStringBase<255> ShortStringBase;  //


The error message is:

[C++Error] sysdefs.h(427): ,expected.
[C++Error] sysdefs.h(428): ,expected.
[C++Error] sysdefs.h(429): ,expected.
[C++Error] sysdefs.h(999): Type name expected.
[C++Error] sysdefs.h(999): Declaration missing ;.
[C++Error] sysdefs.h(1028): 'VString' is not and unambuguous base class of 'System::TVarRec'.
....
....
[C++Error] sysdefs.h(2259): Too many error or warning message.


Please help, I'm new to C++Builder. Thanks.
0
 
LVL 4

Expert Comment

by:wylliker
ID: 2671861
It would seem (I am not familiar with the Builder environment) that you are probably missing some includes that should come before your include of vcl\dstring.h

check the docs or possibly some sample code that might have vcl\dstring.h included and see what that code includes before it.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:nietod
ID: 2672948
You probably need to include <windows.h> at the very least.
0
 
LVL 1

Accepted Solution

by:
jbodom earned 25 total points
ID: 2692279
If you haven't done so, you need to create a new console application via File New and then select the console option.  Once this is done cut and paste the following code to replace any existing code in the file.  This should give you what you need.


#include <condefs.h>
#include <stdio.h>
#include <conio.h>

#pragma hdrstop

#pragma argsused
int main(int argc, char **argv)
{
    String S="Hello World";
    printf(S.c_str());
    printf("\n");
    printf("%d",S.Length());
    getch();
    return 0;
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 2692912
This is not for VC, it is for builder.

Also he is trying to use the VCL string--AnsiString.

jbodom, it is a good idea to reaqd the question history completely before answering.
0
 
LVL 1

Expert Comment

by:jbodom
ID: 2695417
I did read the question history and he answer I proposed is for Borland C++ Builder.  

The AnsiString declaration above may also be used the way I declared it...as String.  When you create a console app in C++ Builder, it (by default) includes the file condefs.h which includes vcl.h.  This will solve his error problem and enable him to use the Length function of AnsiString like he wants.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 2695941
Sorry,   I thought that the "#pragma hdrstop" was VC only.  Borland  usually steals only the good ideas of VC, not the bad. I didn't realize that Borladn also supported that.

Then the solution though is to include vcl.h or condefs.h?
0
 
LVL 1

Expert Comment

by:jbodom
ID: 2696678
When you create a console app in C++ Builder 3, it gives you the option of whether to use vcl (visual component library).  If you wish to use AnsiString, then you should choose to use vcl when creating the console app.  Once this is done, the code is generated for you and certain compiler options are set that are difficult to set up later if you decide to use vcl.  For a beginner, it is much easier to do it this way.  To just include vcl/dstring.h, you must go to project options and add some include/lib directories as well as other options.  saikit must have just deleted this code or never actually went through the process as I described in a previous message.

Builder does use the #pragma hdrstop directive.  It terminates the precompiled header file list.

The solution then would be to follow the procedure described above.  Does this answer the question?
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

18 Experts available now in Live!

Get 1:1 Help Now