Board index » cppbuilder » Is this safe ? property getter and setter for char*
Asger Jorgensen
![]() CBuilder Developer |
Is this safe ? property getter and setter for char*2007-07-05 06:29:17 AM cppbuilder27 Hi there I have been away fro programming for a while so I am a little rusti..;-) So I would like to know if the code below is safe to use. There is of cource a lot more code, I just tok out an example. Thanks in advance Asger h file struct TC5L01 { char Lengde[6]; char Text2[36]; }; class TC5Vare { private: TC5L01* FC5L01; char* __fastcall getLengde(){return FC5L01->Lengde;}; void __fastcall setLengde(char* Value); char* __fastcall getText2(){return FC5L01->Text2;}; public: __property char* Lengde = {read=getLengde, write=setLengde}; __property char* Text2 = {read=getText2}; }; cpp file: //--------------------------------------------------------------------------- void __fastcall TC5Vare::setLengde(char* Value) { char* Str = Value; char* L = FC5L01->Lengde; if(Str[0] == '0') { L[0] = Str[1]; L[1] = '.'; L[2] = Str[2]; L[3] = Str[3]; }else{ L[0] = Str[0]; L[1] = Str[1]; L[2] = '.'; L[3] = Str[2]; L[4] = Str[3]; } } //--------------------------------------------------------------------------- Using the properties: (i am reading a long text file: char* Src) Lengde = &Scr[16]; strcpy(Text1, &Scr[72]); |