hi there, i'm trying to get this get to work but after some clicks (the procedure activates after a click) some text gets messed up, it is some memory mess i guess. anyway take a look, tell me if there's anything wrong (i'm using C++Builder).
void __fastcall TForm1::btnTrac eClick(TObject *Sender)
{
String options;
//options = Application->ExeName;
options = "KanedaX";
int MaxWidth=0,i,ar gc=1;
char **argv=NULL;
char *options_c,*str ;
lstboxFiles->Clear();
//OPTIONS
if (comboFormat->Items->Strings[comboFormat->ItemIndex] != "SVG") {
options += "|-b|" + comboFormat->Items->Strings[comboFormat->ItemIndex];
argc += 2;
}
if (!editOutput->Text.IsEmpty() ) {
options += "|-o|" + editOutput->Text;
argc += 2;
}
//DONE with OPTIONS
//copy String options -> char *options_c
options_c = (char *)malloc(option s.Length()+1);
strcpy(options_ c,options.c_str ());
//start tokenizing
str = strtok(options_ c,"|");
//memory for array of char *
argv = (char**)malloc( argc);
for (i=0; i<argc; ++i) {
//copy each str to argv[i]
argv[i] = (char *)malloc(strlen (str)+1);
strcpy(argv[i],str);
//free mem for both str & options_c (first portion)
// free(str);
//continue tokenizing
str = strtok(NULL,"|" );
}
free(options_c) ;
//show argv on ListBox
for (i=0; i<argc; ++i) {
if (MaxWidth < Canvas->TextWidth(ar gv[i]))
MaxWidth = Canvas->TextWidth(ar gv[i]);
lstboxFiles->Items->Add(argv[i]);
}
//Free mem. for argv
for (i=0; i<argc; ++i) {
free(argv[i]);
argv[i] = NULL;
}
//fix it: memory doesn't get all freed.
// can't figure out why.
//Adjust Width
SendMessage(lst boxFiles->Handle,LB_SETH ORIZONTALEXTENT ,
MaxWidth + 5, 0);
}
void __fastcall TForm1::btnTrac eClick(TObject *Sender)
{
String options;
//options = Application->ExeName;
options = "KanedaX";
int MaxWidth=0,i,ar gc=1;
char **argv=NULL;
char *options_c,*str ;
lstboxFiles->Clear();
//OPTIONS
if (comboFormat->Items->Strings[comboFormat->ItemIndex] != "SVG") {
options += "|-b|" + comboFormat->Items->Strings[comboFormat->ItemIndex];
argc += 2;
}
if (!editOutput->Text.IsEmpty() ) {
options += "|-o|" + editOutput->Text;
argc += 2;
}
//DONE with OPTIONS
//copy String options -> char *options_c
options_c = (char *)malloc(option s.Length()+1);
strcpy(options_ c,options.c_str ());
//start tokenizing
str = strtok(options_ c,"|");
//memory for array of char *
argv = (char**)malloc( argc);
for (i=0; i<argc; ++i) {
//copy each str to argv[i]
argv[i] = (char *)malloc(strlen (str)+1);
strcpy(argv[i],str);
//free mem for both str & options_c (first portion)
// free(str);
//continue tokenizing
str = strtok(NULL,"|" );
}
free(options_c) ;
//show argv on ListBox
for (i=0; i<argc; ++i) {
if (MaxWidth < Canvas->TextWidth(ar gv[i]))
MaxWidth = Canvas->TextWidth(ar gv[i]);
lstboxFiles->Items->Add(argv[i]);
}
//Free mem. for argv
for (i=0; i<argc; ++i) {
free(argv[i]);
argv[i] = NULL;
}
//fix it: memory doesn't get all freed.
// can't figure out why.
//Adjust Width
SendMessage(lst boxFiles->Handle,LB_SETH ORIZONTALEXTENT ,
MaxWidth + 5, 0);
}
Comment