Link to home
Start Free TrialLog in
Avatar of Roger Alcindor
Roger Alcindor

asked on

Embarcadero C++ Builder XE2 TDateTime

In "the good old days" before VCL  Unicode Strings, it was a simple matter to produce an array or characters from a TDateTime formatted in a specific way as follows:

char buff[50];
TDateTime d = d.CurrentDateTime();

memset buff(0,50,0);
sprint(buff,"%s",d.FormatString("dd/mm/yy hh:nn;ss").c_str());
// buff now has the required data ready to send over a serial port or write to a file

With Embarcadero C++ Builder XE2 and later, how can this be coded ?
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

try to add:
char buff[50];
TDateTime d = d.CurrentDateTime();

memset buff(0,50,0);
sprint(buff,"%s",d.FormatString("dd/mm/yy hh:nn;ss").c_str());

AnsiString send_buff = AnsiString(buff, strlen(buff)+1);

Open in new window


...and send send_buff instead of buff itself...
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roger Alcindor
Roger Alcindor

ASKER

Thanks Sara, the following line that I used to populate the buffer was
 BytesToRaw(strDtTm.BytesOf(),buff,strDtTm.Length());
BytesToRaw(strDtTm.BytesOf(),buff,strDtTm.Length());

you may check the length argument. normally it is the size of the output buffer (in bytes) rather than the length of the input string in characters. since you have Unicode String, the size of a character is 2 bytes.

Sara
Sorry, I thought that I had closed the question and assigned points.
I wish to award point to sarabande
thanks, for correction as requested by the author.

Sara