C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

Share tech news, updates, or what's on your mind.

Sign up to Post

I need to generate an XML document based on the result of a database query (ADOQuery).
Is it appropriate to use a TXMLDocument component and if so how would I do this ?
I am writing a VCL application for windows using Embarcadero C++ builder XE 10.1 Berlin
0
I am unable to get any reply from the Getit Package manager in Embarcadero RAD Studio 10.2 or Embarcadero C++ Builder  XE 10.1 Berlin.
Does anyone know when this will be fixed by Embarcadero ?
0
What is the simplest way to the conversion below?
kconn.cpp:35:15: error: non-const lvalue reference to type 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') cannot bind to a value of unrelated type 'const char [4]'
            addRoute("JFK", "ATL", 150);
                     ^~~~~
kconn.cpp:27:31: note: passing argument to parameter 's' here
        void addRoute(std::string &  s,

Open in new window

1
My IDE is visual studio community 2019.  I'm  unable to link GLUT library with my C++ project.  I get following link errors:

link errors
Do I need to specify some windows libraries in "Additional Dependencies" field?


Additional Dependencies
0
I'm using Visual Studio Community 2019.
I found 'OpenGL C++ Tutorial : Getting Started' on youtube.   I get error when I try to link project.  Maybe I'm not specifying 'Additional Dependencies' correctly in my project setting.  Please see attached.

Also, attached is the link error.
Additional_dependencies.PNG
lib_in_proj_folder.PNG
link_error.PNG
0
Hi,

  I  tried to find the free space on mounted volume which is aws elastic filesystem. used statvfs api to find, but statvfs_obj.f_bavail and statvfs_obj.f_blocks are 13digit numbers, statvfs_obj.f_files and statvfs_obj.f_ffree are zeros.

  How to retrieve correct details from mounted aws efs on linux by using statvfs( mounted_filesys_path, &statvfs_struct_obj).  Th path looks like /mnt/efs_mounted_from_xx_city.

  OS: RHEL7.4,

  mount details:  nfs4, rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=xxxx,local_lock=none,addr=xxxxx 0 0


Thanks,
Bvm
0
I have just purchased QuickReport 6.0 Professional and can't get it to compile. to illustrate this I have created a trivial application as follows:
The missing file that appears to be missing is QuickRp.h  (NOT QuickRp.hpp)
I have contacted QBS software for support and they are experiencing the same problem and haven't come up with a solution so far after three days.,
any help would be appreciated.

I have a simple Form (Windows VCL 32bit application) with a TQuickRep control placed on the form and a TQRBand.
The header file of the project is as follows:
class TForm1 : public TForm
{
__published:     // IDE-managed Components
                TQuickRep *QuickRep1;
                TQRBand *QRBand1;
private:                // User declarations
public:                   // User declarations
                __fastcall TForm1(TComponent* Owner);
};
The first attempt to use it with Embarcadero C++ builder XE 10.1 Berlin gives an error messages when I attempt to save the project prior to compilation:
“Unable to find header file for component: QuickRpt”
Pressing cancel results in the same error message being displayed 6 times in total.
 
The code doesn’t compile as the header files are missing and the compiler error “Type name expected” is given (naturally)
 
The installation ran without any errors using the downloaded file QuickReportv6QR6DXE10_1_Berlin_W64_installer.exe
The PC is a Dell Precision laptop running 64 bit windows 7 Professional …
0
I have just installed Embarcadero 10.2 RAD and every project I try to build or compile returns the following error without referencing any line in the project. Even new projects that I create with nothing in them are giving this error.

[Fatal Error] Object reference not set to an instance of an object
0
I am using GetPrivateProfileString to retrieve some data for a program I am working on. Can anyone tell me why the code below does not work as well as which it often breaks at runtime.

LPCTSTR lpAppName2;
LPCTSTR lpKeyName2;
LPCTSTR lpDefault;
LPTSTR  lpReturnedString;
DWORD   nSize;
LPCTSTR lpFileName2;

	GetPrivateProfileString(
		lpAppName2 = TEXT ("Section11"),
		lpKeyName2 = TEXT ("FirstKey1"),
		lpDefault  = TEXT ("String Not Found") ,
		lpReturnedString ,
		nSize ,
		lpFileName2 = TEXT ("c:\\aa\\test2.ini")
		);
	Application->ProcessMessages();
	ShowMessage(lpReturnedString);

Open in new window

0
Is it possible to hide the main form in a Windows application written in Embarcadero C++ builder XE 10.1  ?
0
I'm trying to declare an array for a graph problem in class.  When I try and print the arrays I get an "expression must have class type" error.

#pragma once
#ifndef GRAPH_H
#define GRAPH_H
#include <list>
#include <vector>
#include <string>
#include <set>

class Graph {
private:
	static const int MAXIMUM = 20;
	int mileageGraph[MAXIMUM][MAXIMUM];  //compiles so long as I comment out my print function
	int costGraph[MAXIMUM][MAXIMUM];
	std::vector<std::string> vertex;
	//int labels[MAXIMUM];
	int manyVertices;

public:  //this is where the functions go

	Graph();
	void addVertex(const std::string value);
	int getMileage(int source, int destination);
	int getCost(int source, int destination);
	void addEdge(int source, int destination, int mileage, int cost);
	bool isEdge(int source, int destination) const;
	//void shortestPath(int source);
	int getID(std::string vertex);
	std::string getName(int vertexId);
	int size();
	void printDirectFlights();
};

#endif // !GRAPH_H

void Graph::printDirectFlights()
{
	cout << "Direct Flights" << endl;
	cout << left <<
		setw(10) << "Source" <<
		setw(15) << "Destination" <<
		setw(10) << "Mileage" <<
		setw(10) << "Price" << '\n';
	for (int i = 1; i < MAXIMUM; i++)
	{
		for (int j = 1; j < MAXIMUM; j++)
		{
			if (costGraph.isEdge(i, j))  //breaks
			{
				cout << left <<
					setw(10) << getName(i) <<
					setw(15) << getName(j) <<
					setw(10) << mileageGraph.getMileage(i, j) <<  //breaks
					setw(10) << costGraph.getCost(i, j)

Open in new window

0
I am having a problem with an old function I used to use about 20 years ago.
I am using Embarcadero RAD 8.3

I have added windows.h to my include list
AnsiString name;
GetPrivateProfileString(_T("Section 1"), _T("Key 1"), _T("") , name, 32, _T("C:\\test.ini"));

Open in new window

This is the error I am getting when I try to compile

[bcc32c Error] Unit2.cpp(53): no matching function for call to 'GetPrivateProfileStringW'

I find this most confusing.
0
Hi,

I am having a problem with Indy in Embarcadero RAD 10.3. I am using the version of Indy that RAD 10.3 shipped with. I am getting a timeout error with MyPoP->Connect();

MyPop3->Host = "host";
MyPop3->Username = "username";
MyPop3->Password = "password";
MyPop3->Port = 995;
MyPop3->Connect();

This is the error I am getting.
Capture_13.jpg
0
I am using Embarcadero C++ builder XE10.1 Berlin update 2.I am having trouble sorting a  TList .
To illustrate the problem, I have coded a simple example below which generates 30 random integers and puts them into a class which is added into a list.
The original list content is displayed in Memo1. the list is sorted using a compare function and the sorted list is displayed in Memo2.
The resultant display shows that the sort operation fails. I have inspected the comarisons by setting a breakpoint in the compare function and can see no failure there.
What am I doing wrong ?

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
using namespace std;
#include <list>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

class MyClass
{
	public:
	int n;
	MyClass(int a){n=a;};
	~MyClass(){};
};

int SortOnInt(void *Item1, void *Item2)
{
	MyClass *a = reinterpret_cast<MyClass *>(Item1);
	MyClass *b = reinterpret_cast<MyClass *>(Item2);
	int rtn = 0;

	if(a!=NULL && b!=NULL)
	{
		if(a->n  > b->n)
			rtn = 1;
		else
		if(a->n  < b->n)
			rtn = -1;
	}
	return rtn;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	list<MyClass *> myclasslist;
	list<MyClass *>::iterator k;
	int i,j;

	Memo1->Clear();
	Memo2->Clear();

Open in new window

0
I am having trouble sorting an STL list of pointers to a class based on a DtateTime member of the class.

My code is as follows and the result of the sort is a partial sort but there are a few items that are mis-placed.
I am using embarcadero C++ builder XE10.1 Berlin update 2 and building a Windows 32 application

class TTorqueString
{
	public:
	int id;
    	UnicodeString prodline; // production line (FL1,RL1,FL2 or RL2)
	TDateTime timestamp;
	int stationindex;
	UnicodeString stationname;
    	UnicodeString errortype;
	UnicodeString torquestring;
    	TTorqueString(TDataSet *ds);
	TTorqueString();
	~TTorqueString();
	void Clear(void);
	void DecodeRawInput(UnicodeString u);
    	UnicodeString MemoString(void);
};

typedef list<TTorqueString *>TSList;


int SortOnDateTime(void *Item1, void *Item2)
{
	TTorqueString *a = reinterpret_cast<TTorqueString *>(Item1);

	TTorqueString *b = reinterpret_cast<TTorqueString *>(Item2);
	int rtn = 0;

	if(a!=NULL && b!=NULL)
	{
		if((double)(a->timestamp)>(double)(b->timestamp))
			rtn = 1;
		else
		if((double)(a->timestamp)<(double)(b->timestamp))
            		rtn = -1;
	}
	if(DataModule2->ascending)
		rtn = -rtn;

	return rtn;
}


TSList tslog;
// gets initialised with values ...

// now to sort the list

tslog.sort(SortOnDateTime);  // sorts but not correctly 

Open in new window


I attach a partial view of the sorted list. The out of place items all have a date of 30/12/1899 which corresponds to a zero value of the TDateTime.
I'm guessing that this value has something to do with it. These items should appear at the end of the sorted list but they don't. they appear somewhere in between the start and end.
Sorted List
0
Goal: Install C++ through a GPO to Windows 7 and Windows 10 PC's.

When looking at this site:
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

I am trying to silently push out the following file:
Microsoft Site
Unfortunately it's an EXE, so I can't easily push it out via Group Policy.
Can someone help me accomplish a silent install?
0
I have not been able to implement an event handler for a StringGrid OnMousedown event when the stringGrid is a multi-platform application with a target of Windows 32.
the compiler (C++ builder Embarcadero XE 10.1Berlin) gives a compile time error where the event handler is assigned in the constructor for the form Form3.

[bcc32 Error] Unit3.cpp(17): E2034 Cannot convert 'void (_fastcall * (_closure )(TObject *,TMouseButton,TShiftState,int,int))(TObject *,TMouseButton,TShiftState,int,int)' to 'TMouseEvent'
  Full parser context
    Unit3.cpp(15): parsing:  _fastcall TForm3::TForm3(TComponent *)

the code is as follows:

__fastcall TForm3::TForm3(TComponent* Owner)
	: TForm(Owner)
{
	StringGrid1->OnMouseDown = StringGrid1MouseDown; // <-----This giver a compile error
}
//---------------------------------------------------------------------------
void __fastcall TForm3::StringGrid1MouseDown(TObject *Sender, TMouseButton Button,
		  TShiftState Shift, int X, int Y)

{
	TStringGrid *g;
	int col, row;
	bool fixedCol, fixedRow;

// ... code to handle mouse-down event
}

Open in new window


Can this be corrected ?
0
I am trying to get the exif data from a jpeg image file using the Magick++ attribute approach but I get link errors LNK2028 and LNK2019 for the image object instance attribute. The environment is Visual Studio Community Edition 2017. The version of ImageMagick is 6.9.3-7 compiled with the Magick++ headers. The operating system is Windows 10. I get the same issue when trying to use the latest Windows version of Image Magick similarly compiled.

The exif data are there via the Windows command line indentify -verbose filename.

The Magick++ methods that I am using such as read, quality, resize and write all link and work fine but the attribute does not - (standard string) extracted_data = image.attribute("exif:DateTime"); gives the link errors.

Further information: On a separate Windows 7 PC the identical C++ code compiles, links and executes perfectly. On that PC the IDE is Visual Studio 2010 Express with ImageMagick 6.8.6.

Any advice will be most appreciated and thanking you in anticipation.
0
Hi, I have a cpprestsdk test program which calls a PHP back-end on my localhost passing GET data and this works fine.  But I want to pass the data via POST rather than GET and though I have Googled intensely I cannot get any of the suggestions to work in my environment which is Win 10 and VS2019.
I've attached the GET code which works.
If you can advise me how to achieve the similar functionality but sending the data to the backend via POST I would be most appreciative and thank you in anticipation.part 1 of the codepart 2 of the code
0
I am having trouble receiving UDP broadcast traffic using the  Indy 10  TIdUDPServer component with Embarcadero XE 10.1 Berlin Update 2 C++ compiler.
I can see the broadcast traffic using Wireshark but the OnUDPRead event does not get triggered.

The TIdUDPServer bindings are 0.0.0.0:13579

My event handler is as follows:

void __fastcall TForm1::IdUDPServer1UDPRead(TIdUDPListenerThread *AThread, const TIdBytes AData,
		  TIdSocketHandle *ABinding)
{
	UnicodeString u;

	u = BytesToString(AData);
	Edit1->Text = AThread->Binding->PeerIP;
    Memo1->Lines->Add(u);
}

Open in new window


In order for the event to be triggered, I have to change the client code to use the unicast address of the server, in this case 192.168.1.77.

I have tries broadcast addresses of 192.168.1 255 and 255.255.255.255 but neither works.
The client is on another windows machine which has an IP address of 192.168 1.235

What am I missing or doing wrong ?
0
In Item 6 of his book "Effective C++" (Third Edition), Scott Myers gives the following example of an "uncopyable" base class, which can be used to disable the copy constructor and assignment operator in derived classes:

class Uncopyable
{
protected:
	Uncopyable() {}
	~Uncopyable() {}

private:
	Uncopyable(const Uncopyable&);
	Uncopyable& operator=(const Uncopyable&);
};

Open in new window

One then does the following:

class Derived : private Uncopyable { ... };

Open in new window

I can see that this works, however I am puzzled by two things:

1. Why is private inheritance used instead of public?
2. Why does it make any difference if Uncopyable's constructor and destructor are declared protected or private? After all, with private inheritance all base class methods become private in the derived class.

Thanks.
0
Which header file in Embarcadero C++ builder XE10.1 is appropriate for us when declaring a TDynBytesArray variable  such as that needed by the RawtoBytes function ?
0
I have a set of lights ws2812 tha are addressible using the FASTLED library on a Arduino writen in C .

The code below makes this animation:  ○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙○◙ --------->  on a LED strip

The lights are working great in its current direction. I need the lights to travel now in the opposite direction.  Thank you.

#include <FastLED.h>

// Define the array of leds
#define LED_DT 3
#define COLOR_ORDER GRB
#define LED_TYPE WS2812
#define NUM_LEDS 38
uint8_t max_bright = 255;
struct CRGB leds[NUM_LEDS];


void setLEDs (int K, int N) {
  FastLED.clear();
for (int i = 0; i < NUM_LEDS; i++) {
    //( int i = NUM_LEDS-1; i >=0; i–-)  //  tried this but it didnt work
    if (i % N == K) leds[i].setRGB (0, 0, 250); // set red LED
  }
  FastLED.show();
}

void setup() {
  delay (1000);
  LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(max_bright);
}

void loop() {
  int N = 5;
  for  (int i = 0; i < N; i++) {
    setLEDs (i, N);
    delay (150);
  }
}

Open in new window

0
I am writing a C++ builder VCL application using embarcadero XE10.1.
I have a TMemo control on the main form and wish to determine the line of text in the Memo window that is clicked on with a mouse.
The TMemo control has several lines of text.
I suspect that the OnMouseDown event handler could be used but I need to know how to determine the line of text corresponding to the Y value in the event handler ?

Thanks,

Roger
0
I have problems to understand a structure padding code from another developer done.  In the code there are some size check functions availbale:

Main issue:
CHECK_SIZE(SCreateImageParams, 2150);

Open in new window


where this is defined in:

	template<bool Ok>
	struct STATIC_ASSERTION_FAILURE;

	template<>
	struct STATIC_ASSERTION_FAILURE<true>{};
	
	template <int size>
	struct SIZEOF_GETTER
	{
	};
	
	#define CHECK_SIZE(TheTypeName, ExpectedSize)	\
		namespace									\
		{											\
			typedef char mytype[ sizeof( STATIC_ASSERTION_FAILURE< (ExpectedSize) == sizeof(TheTypeName)  >  ) ]; \
		}


#else // #ifdef __cplusplus
	#define CHECK_SIZE(TheTypeName, ExpectedSize)
#endif // #ifdef __cplusplus

Open in new window


Now in this special structure I have in header file:

	struct SCreateImageParams
	{
		TCHAR	lpszImagePath[_MAX_PATH];
		TCHAR	lpszBadSectorsFilePath[_MAX_PATH];
		int16	nImageType;
		int32	nVerifyBufferSize;
		SReadErrorCorrectionParams cErrorParams;
					
		INSERT_STRUCTURE_PADDING(STRUCTURE_PADDING_STRING_DATA);

#ifdef __cplusplus
		SCreateImageParams()
			:nImageType(BS_IMG_ISO)
			,nVerifyBufferSize(1)
		{
			StrCpy(lpszImagePath, _T(""));
			StrCpy(lpszBadSectorsFilePath, _T(""));
		}
#endif
	};

Open in new window


Here I have added new:
int32	nVerifyBufferSize;

Open in new window


The Padding is defined as:

#ifndef _MAX_PATH
#	define _MAX_PATH			260
#endif

//// end (needed defines)

//	Padding Definitions
#define INSERT_STRUCTURE_PADDING(nBytes)	\
	int8 x__the_private_padding[(nBytes)];		
		
#define STRUCTURE_PADDING_STRING_DATA	( (4*sizeof(void*) + 32)   +   2 * (_MAX_PATH) * sizeof(TCHAR) )
#define STRUCTURE_PADDING_HUGE			(4*sizeof(void*) + 32 * sizeof(TCHAR) )
#define STRUCTURE_PADDING_BIG			(3*sizeof(void*) + 16)
#define STRUCTURE_PADDING_NORMAL		(2*sizeof(void*) + 8)
#define STRUCTURE_PADDING_SMALL			(sizeof(void*) + 4)

	
//	End of Padding Definitions


//// BOOL
#	define int2bool(nTmp)						(0 != nTmp)
#	define BOOL2bool(bTmp)						(FALSE != bTmp)
#	define BS_BOOL2bool(bTmp)					(BS_FALSE != bTmp)
#	define int2BS_BOOL(nTmp)					((0 != nTmp) ? BS_TRUE : BS_FALSE)

#	define BS_NDEF								-1							// -> BS_NDEF is interpreted as BS_TRUE.
#	define BS_BOOL								int8
#	define BS_LP_BOOL							int8*
#	define BS_FALSE								0
#	define BS_TRUE								1

Open in new window


Now I get compiler erors that the checksize do not work well.

1>d:\development\6.8.4\development\sdk\export.cpp(1678): error C2027: Verwendung des undefinierten Typs "STATIC_ASSERTION_FAILURE<false>"
1>d:\development\6.8.4\development\sdk\export.cpp(1678): note: Siehe Deklaration von "STATIC_ASSERTION_FAILURE<false>"
1>d:\development\6.8.4\development\sdk\export.cpp(1678): error C2466: Zuordnung eines Arrays der konstanten Größe 0 nicht möglich.
1>d:\development\6.8.4\development\sdk\export.cpp(1678): error C2086: "char `anonymous-namespace'::mytype[1]": Neudefinition

Open in new window


All in case of the main issue on top. My question is now what I have to change that the new structure will work well.
I assume that I have to increase the size from 2150 to 2158 and the padding will still remain the same. But this will not work.
Can anyone explain me the functionality?
0

C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.