Solved

Fail to declare AnsiString

Posted on 2000-03-30
11
345 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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.

775 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