Board index » cppbuilder » TListview->Items->Add() bug ? BCB4

TListview->Items->Add() bug ? BCB4

I have Borland C++ Builder 4 professional end the two patches installed.

I am making a compression program.

I use a ListView to represent a directory structure, I wrote my own routine
to read the current directory, no problems here.

When I enter an archive, and use the same function as above, except I use
fread to read the fileheaders and not FindFirst (I use the vcl findfirst and
not the dos one, in the previous version of my program I used the dos
findfirst) and so on, **sometimes** the function ListView->Items->Add()
performs an illegal operation for no obvious reason.
I first clear the ListView with ListView->Items->Clear().
The illegal operation is **always** performed with the second add().
The first add() isn't in a loop, the rest is.

I tried every possible action I can think of, but it is always the same.

I don't know if it's my code or if it's BCB4, but BCB4 is acting strange
lately. The previous version of my program hadn't any problems, and the code
is exactly the same, but it was a different compiler (BCB3). I imported the
code in BCB4 and the problem occured, then I started from scratch and I
totally rewrote the thing, but the problem remains.

If it is any help, I can post the code snippets.

Please help.
Thanks

Philipp

 

Re:TListview->Items->Add() bug ? BCB4


Post some code please.

Brent

Quote
Philipp <pdru...@pdp.be> wrote in message

news:85envd$3qa5@bornews.borland.com...
Quote
> I have Borland C++ Builder 4 professional end the two patches installed.

> I am making a compression program.

> I use a ListView to represent a directory structure, I wrote my own
routine
> to read the current directory, no problems here.

> When I enter an archive, and use the same function as above, except I use
> fread to read the fileheaders and not FindFirst (I use the vcl findfirst
and
> not the dos one, in the previous version of my program I used the dos
> findfirst) and so on, **sometimes** the function ListView->Items->Add()
> performs an illegal operation for no obvious reason.
> I first clear the ListView with ListView->Items->Clear().
> The illegal operation is **always** performed with the second add().
> The first add() isn't in a loop, the rest is.

> I tried every possible action I can think of, but it is always the same.

> I don't know if it's my code or if it's BCB4, but BCB4 is acting strange
> lately. The previous version of my program hadn't any problems, and the
code
> is exactly the same, but it was a different compiler (BCB3). I imported
the
> code in BCB4 and the problem occured, then I started from scratch and I
> totally rewrote the thing, but the problem remains.

> If it is any help, I can post the code snippets.

> Please help.
> Thanks

> Philipp

Re:TListview->Items->Add() bug ? BCB4


Quote
: "Philipp" <pdru...@pdp.be> wrote:
>**sometimes** the function ListView->Items->Add()
>performs an illegal operation for no obvious reason.

This definitely is your code.

Quote
>If it is any help, I can post the code snippets.

Please do - but please only 20 lines maximum. Thank you.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:TListview->Items->Add() bug ? BCB4


It goes like this

void __fastcall Main::ReadInArchive(void)
{
FILE *p;
ListView->Items->Clear(); // must be done because the ListView is filled
with the current dir, the listview is never empty
ListView->Items->Add();
Listview->Items->Item[0]->Caption = "..";
p=fopen("test.dat","rb");
for (int x = 1; x <= numberoffiles; x++)
{
    fread(&files,sizeof(files),1,p); // the contents of files after fread
are correct, i checked, filenames are never bigger than 20 chars
    Listview->Items->Add(); // the illegal operation is performed here the
first time we go in the loop, **never** the second time for example
    // I also tried ListView->Items->Insert(x) , same effect
    Listview->Items->Item[x]->Caption = files.filename; // files.filename is
a char[256]
    // also tried with
strcpy(ListView->Items->Item[x]->Caption.c_str(),files.filename);

Quote
}
fclose(p);
}

Philipp <pdru...@pdp.be> schreef in berichtnieuws
85envd$3...@bornews.borland.com...
Quote
> I have Borland C++ Builder 4 professional end the two patches installed.

> I am making a compression program.

> I use a ListView to represent a directory structure, I wrote my own
routine
> to read the current directory, no problems here.

> When I enter an archive, and use the same function as above, except I use
> fread to read the fileheaders and not FindFirst (I use the vcl findfirst
and
> not the dos one, in the previous version of my program I used the dos
> findfirst) and so on, **sometimes** the function ListView->Items->Add()
> performs an illegal operation for no obvious reason.
> I first clear the ListView with ListView->Items->Clear().
> The illegal operation is **always** performed with the second add().
> The first add() isn't in a loop, the rest is.

> I tried every possible action I can think of, but it is always the same.

> I don't know if it's my code or if it's BCB4, but BCB4 is acting strange
> lately. The previous version of my program hadn't any problems, and the
code
> is exactly the same, but it was a different compiler (BCB3). I imported
the
> code in BCB4 and the problem occured, then I started from scratch and I
> totally rewrote the thing, but the problem remains.

> If it is any help, I can post the code snippets.

> Please help.
> Thanks

> Philipp

Re:TListview->Items->Add() bug ? BCB4


Quote
: "Philipp" <pdru...@pdp.be> wrote:

Philipp, I would appreciate it if you wouldn't change the subject of a
message needlessly, because that breaks threading. Thank you.

Also I would appreciate it if you could post your compiling, actual source
code, because this:

Quote
>ListView->Items->Add();
>Listview->Items->Item[0]->Caption = "..";

definitely will never compile.

It is therefore questionable whether

  TListItem* ListItem;
  ListItem = ListView->Items->Add();
  ListItem->Caption = "..";

will solve your problem, since you didn't bother to post your actual
source code.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:TListview->Items->Add() bug ? BCB4


the actual code is:

DirList->Items->Add(); // first item
Dirlist->Items->Item[0]->Caption="..";

And it does compile. It has always compiled!
And the first item in the listview is  ..

Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> schreef in
berichtnieuws ba8m7s85ocskelu18t8k0qdr1p4cqnn...@4ax.com...

Quote
> : "Philipp" <pdru...@pdp.be> wrote:

> Philipp, I would appreciate it if you wouldn't change the subject of a
> message needlessly, because that breaks threading. Thank you.

> Also I would appreciate it if you could post your compiling, actual source
> code, because this:

> >ListView->Items->Add();
> >Listview->Items->Item[0]->Caption = "..";

> definitely will never compile.

> It is therefore questionable whether

>   TListItem* ListItem;
>   ListItem = ListView->Items->Add();
>   ListItem->Caption = "..";

> will solve your problem, since you didn't bother to post your actual
> source code.

> --
> General information:
>   * Post to the right group - http://www.borland.com/newsgroups/
>     * Do not cross- or multipost
>       * Research at http://www.mers.com/searchsite.html

> Stefan Hoffmeister - http://www.econos.de/
> TeamB - http://www.teamb.com/

Re:TListview->Items->Add() bug ? BCB4


Quote
: "Philipp" <pdru...@pdp.be> wrote:
>the actual code is:

>DirList->Items->Add(); // first item
>Dirlist->Items->Item[0]->Caption="..";

>And it does compile.

Philipp, this cannot compile. C++ is a case-sensitive language.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:TListview->Items->Add() bug ? BCB4


Sorry, it's twice DirList. I'm wrong... it was a type fault of me

Is this the solution ?

  TListItem* ListItem;
  ListItem = DirList->Items->Add();
  ListItem->Caption = "..";

Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> schreef in
berichtnieuws ugbm7sgpctv4ramhj8o95sb7ceu6k3s...@4ax.com...

Quote
> : "Philipp" <pdru...@pdp.be> wrote:

> >the actual code is:

> >DirList->Items->Add(); // first item
> >Dirlist->Items->Item[0]->Caption="..";

> >And it does compile.

> Philipp, this cannot compile. C++ is a case-sensitive language.

> --
> General information:
>   * Post to the right group - http://www.borland.com/newsgroups/
>     * Do not cross- or multipost
>       * Research at http://www.mers.com/searchsite.html

> Stefan Hoffmeister - http://www.econos.de/
> TeamB - http://www.teamb.com/

Re:TListview->Items->Add() bug ? BCB4


Quote
: "Philipp" <pdru...@pdp.be> wrote:
>Sorry, it's twice DirList. I'm wrong... it was a type fault of me

>Is this the solution ?

>  TListItem* ListItem;
>  ListItem = DirList->Items->Add();
>  ListItem->Caption = "..";

Well, it certainly will speed up your adding.

It is well possible that your insertion code with all these pointers is
responsible.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:TListview->Items->Add() bug ? BCB4


Thanks
I will certainly try it this evening ( I'm at work now ), and I'll let you
know.
Can I mail you directly ? Or do you prefer this newsgroup ?

Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> schreef in
berichtnieuws rsdm7sod49r38n72frua3dqrapdhp92...@4ax.com...

Quote
> : "Philipp" <pdru...@pdp.be> wrote:

> >Sorry, it's twice DirList. I'm wrong... it was a type fault of me

> >Is this the solution ?

> >  TListItem* ListItem;
> >  ListItem = DirList->Items->Add();
> >  ListItem->Caption = "..";

> Well, it certainly will speed up your adding.

> It is well possible that your insertion code with all these pointers is
> responsible.

> --
> General information:
>   * Post to the right group - http://www.borland.com/newsgroups/
>     * Do not cross- or multipost
>       * Research at http://www.mers.com/searchsite.html

> Stefan Hoffmeister - http://www.econos.de/
> TeamB - http://www.teamb.com/

Re:TListview->Items->Add() bug ? BCB4


Quote
: "Philipp" <pdru...@pdp.be> wrote:
>Can I mail you directly  

All mail that gets sent to me with a reference to a newsgroup posting is
auto-bounced - so the answer is no, I suppose :-)

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Other Threads