Поиск:

Ответ в темуСоздание новой темы Создание опроса
> EAccessViolationException help 
V
    Опции темы
StrikeTheCore
Дата 20.6.2006, 00:14 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 11
Регистрация: 25.5.2006

Репутация: нет
Всего: нет



I have code running that constantly throws an Access Violation on Windows XP. This exception only occurs however after around 10 to 20 thousand times running this function. I can catch the exception but want to get rid of it completely, however cannot figure out where it is coming from. Code is below (str is a simple string parser). Any help is greatly appreciated.

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

        unsigned char *inbuffer;
        AnsiString tmp;
        struct timeval current;
        inbuffer = new unsigned char[Count+2];
        myComPort->Read(inbuffer, Count);
        str.reset();
        try {
        if(Form2->mode == TForm2::HEX_MODE && !Form2->BufferDisabled->Checked){
                for(int i=0; i<Count; i++){
                        tmp.sprintf("%0x ", inbuffer[i]);
                        if(tmp.Length() < 3)
                                tmp = AnsiString("0") + tmp;
                        str << tmp.c_str() << " ";
                }
                if(Form2->ReceiveBuffer.Length() + str.length() < Form2->MaxBufLen){
                        Form2->ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
                }
                else{
                        unsigned int n=0;
                        for(int count=0;n<=str.length();count++)
                                n += (*(Form2->Memo->Lines))[count].Length();
                        Form2->ReceiveBuffer.Delete(0, n);
                        Form2->ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
                }
        }
        else if(Form2->mode == TForm2::ASCII_MODE && !Form2->BufferDisabled->Checked){
                inbuffer[Count] = '\0';
                if(Form2->ReceiveBuffer.Length() + strlen((char*)inbuffer) > Form2->MaxBufLen){
                        Form2->ReceiveBuffer.Delete(0, strlen((char*)inbuffer));
                }
                Form2->ReceiveBuffer += AnsiString((char*)inbuffer);
                if(Form2->logdata){
                        std::ofstream outfile;
                        outfile.open(Form2->LogFileName.c_str(), std::ofstream::out | std::ofstream::app);
                        outfile << (char*)inbuffer;
                        outfile.close();
                }
        }
        }
        catch (const EAccessViolation & vae)
        {
                ShowMessage("Misread message");
        } 
PM MAIL   Вверх
Vyacheslav
Дата 20.6.2006, 09:18 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Экс. модератор
Сообщений: 2124
Регистрация: 25.3.2002
Где: Москва

Репутация: 47
Всего: 59



Is  Form2->ReceiveBuffer  AnsiString?  If this is AnsiString,  the first  argument  in Delete has to be  larger than 0 and less than Length of the AnsiString. See help
Цитата

Removes a specified number of characters from the string.

AnsiString& __fastcall Delete(int index, int count);

Description

Delete modifies the AnsiString to remove count characters from the string beginning with the character at index, where 1 is the index of the first character. It returns the resulting modified string (*this).

If index is larger than the length of the AnsiString or less than 1, no characters are deleted.

If count specifies more characters than remain starting at the index, Delete removes the rest of the string. If count is less than 0, no characters are deleted.
 


--------------------
С уважением, Вячеслав Ермолаев
PM MAIL WWW ICQ   Вверх
StrikeTheCore
Дата 20.6.2006, 16:18 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 11
Регистрация: 25.5.2006

Репутация: нет
Всего: нет



Thanks a lot, that solved the problem. I guess I'm so used to Java and string indexes starting at 0 that I didn't even consider the possibility that this could be the source of the problem. 
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "С++ Builder"
Rrader

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Литературу по С++ Builder обсуждаем здесь
  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Настоятельно рекомендуем заглянуть в DRKB (Delphi Russian Knowledge Base) - крупнейший в рунете сборник материалов по Дельфи


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Rrader.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C++ Builder | Следующая тема »


 




[ Время генерации скрипта: 0.1065 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.