
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[216.73.216.21] |
![]() |
|
Сообщ.
#1
,
|
|
|
При создании проекта с использованием собственного компонента столкнулся со следующей проблемой:
При запуске C++Builder2009 и открытии группы проектов/главного проекта (на ошибку не влияет), в котором используется самописный компонент. Вылетает ошибка: Title = "Error reading form" Text = "Can't load package my_package. Неверная попытка доступа к памяти. ..." Жму Игнор, чтобы сохранить положенный на главную форму проекта компонент и его свойства. После чего вылетает еще одна ошибка: title = "Error creating form" Text = "Can't load package my_package. Неверная попытка доступа к памяти." После этого открывается модуль главной формы проекта, но без вкладки дизайна формы. Если после этого закрыть главный модуль в редакторе и переустановить пакет с компонентом, то главная форма и открывается в редакторе, и само приложение работает без каких-либо ошибок. Пока опять не запущу Builder по новой. Подскажите, пожалуйста, в чем может быть ошибка и как ее поймать. |
![]() |
Сообщ.
#2
,
|
|
Не прописан путь BPL-ки самописного копонента в системном PATHе.
Самое простое - кинуть ее в папку по умолчанию с BPL-ками (для 6-го Билдера это: C:\Program Files\Borland\CBuilder6\Projects\Bpl) которая добавляется в PATH при установке Билдера. |
Сообщ.
#3
,
|
|
|
2 Chow:
Пробовал положить мою .bpl в директории, где лежат .bpl Builder'a, в C++Builder2009 это следующие директории: C:\Program Files\CodeGear\RAD Studio\6.0\bin C:\WINDOWS\system32 - сообщение об ошибке все также появляется и с тем же самым текстом. Еще пробовал переименовать файл моей *.bpl, чтобы посмотреть как реагирует Builder если не может ее найти - появляется ошибка, но другая (не может найти пакет)!!! Собственно получается где-то, что-то надо править ... ох если бы эта ошибка "доступа к памяти" проявлялась при запуске приложения, тогда можно было бы отдалиться, а так ![]() Вот привожу основные фрагменты кода м.б. кто-нибудь сразу ее определит на глаз: .h ![]() ![]() #ifndef TLessListBoxH #define TLessListBoxH //--------------------------------------------------------------------------- #include <SysUtils.hpp> #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <stdio.h> #include <vector> //--------------------------------------------------------------------------- class PACKAGE TLessListBox : public TCustomListBox { public: /* operation modes (with a File, with a COM Port) */ enum mode_t { file_mode, port_mode }; private: /* default configuration values */ static const size_t def_wnd_size = 10000; // specifies a buffer size static const size_t def_frontier_size = 1000; //specifies a frontier size static const size_t def_max_line_len = 256; size_t Fwnd_size; // specifies a buffer size size_t Ffrontier_size; // specifies a frontier of a window size_t Fmax_line_len; int displayed_lines; // number of lines displaying at the moment struct buf_t { size_t first_line; // number of the first line of the buffer TStringList *pList; void copyto(buf_t *dest); }; buf_t buf1, buf2; //actual buffers to store wnd_size lines of the file buf_t *main_buf; // pointer to a buffer which is primary now buf_t *hot_swap_buf;// pointer to a buffer which is hot swap now /* current operation modes */ mode_t mode; // current operation mode FILE *fp; // pointer to a FILE of a file to display std::vector <long int> ovec;// vector of boundary points offsets /* Critical section to support COM operations with threads */ TCriticalSection *COM_Critical; bool reenter; // to prevent reenter in COM_Pause static const wchar_t *NotAvailStr;//denotes: line is not available online protected: virtual void __fastcall Loaded(void); void __fastcall OnDataHandler(TWinControl *Control, int Index, UnicodeString &Data) throw (Exception); void __fastcall OnDataHelperFile(int Index, UnicodeString &line); void __fastcall LoadWnd(int wnd_idx, buf_t * pbuf) throw (Exception); void __fastcall OnDataHelperPort(int Index, UnicodeString &line) throw (Exception); void setup_displayed_lines() { displayed_lines = Height / ItemHeight; }; void __fastcall OnResizeHandler(TObject* Sender); public: __fastcall TLessListBox(TComponent* Owner) throw (Exception); virtual __fastcall ~TLessListBox(); virtual void __fastcall Clear(); enum wpos_t { wTop, wMiddle, wBottom}; void __fastcall GoTo(int LineNum, wpos_t pos); void __fastcall DisplayFile(UnicodeString FileName) throw (Exception); void __fastcall DisplayPort(); void __fastcall COM_Append(char *line) throw (Exception); void __fastcall COM_Update(); void __fastcall COM_Pause() throw(Exception); void __fastcall COM_Resume() throw(Exception); bool __fastcall COM_Is_Paused() { return reenter; }; static const wchar_t *GetNotAvailStr() { return NotAvailStr; }; /* get current operation mode */ mode_t get_mode() { return mode; }; /* get delta between Integral Height and Non Integral Height */ int __fastcall GetIntegralHeightDelta(); __published: __property size_t wnd_size = { read = Fwnd_size, write = Fwnd_size, default = def_wnd_size }; __property size_t frontier_size = { read = Ffrontier_size, write = Ffrontier_size, default = def_frontier_size }; __property size_t max_line_len = { read = Fmax_line_len, write = Fmax_line_len, default = def_max_line_len }; /* specify default properties values */ __property Align = {default=0}; __property Anchors = { default=3}; __property BevelEdges = { default=15}; __property BevelInner = { index=0, default=2}; __property BevelKind = {default=0}; __property BevelOuter = { index=1, default=1}; __property BevelWidth = { default=1}; __property BorderStyle = { default=1}; __property Color = { default=-16777211}; __property Constraints; __property Enabled = { default=1}; __property Font; __property ItemHeight; __property ParentColor = { default=0}; __property ParentFont = { default=1}; __property ParentShowHint = { default=1}; __property ShowHint; __property TabOrder = { default=-1}; __property TabStop = { default=1}; __property TabWidth = { default=0}; __property Visible = { default=1}; __property OnClick; __property OnDblClick; __property OnDragDrop; __property OnDragOver; __property OnEndDock; __property OnEndDrag; __property OnEnter; __property OnExit; __property OnKeyDown; __property OnKeyPress; __property OnKeyUp; __property OnMeasureItem; __property OnMouseActivate; __property OnMouseDown; __property OnMouseEnter; __property OnMouseLeave; __property OnMouseMove; __property OnMouseUp; __property OnStartDock; __property OnStartDrag; }; //--------------------------------------------------------------------------- #endif часть .cpp, относящаяся к созданию/удалению компонента: ![]() ![]() #include <vcl.h> #pragma hdrstop #include <vector> #include <math.h> #include "TLessListBox.h" #pragma package(smart_init) //--------------------------------------------------------------------------- // ValidCtrCheck is used to assure that the components created do not have // any pure virtual functions. // static inline void ValidCtrCheck(TLessListBox *) { new TLessListBox(NULL); } //--------------------------------------------------------------------------- const wchar_t *TLessListBox::NotAvailStr = L" line is not available online"; __fastcall TLessListBox::TLessListBox(TComponent* Owner) throw (Exception) : TCustomListBox(Owner), Fwnd_size(def_wnd_size), Ffrontier_size(def_frontier_size), Fmax_line_len(def_max_line_len), reenter(false) { try { /* allocate memory for buffers */ buf1.pList = new TStringList; buf2.pList = new TStringList; COM_Critical = new TCriticalSection; } catch (std::bad_alloc) { delete buf1.pList; delete buf2.pList; delete COM_Critical; throw Exception(L"Cannot create TLessListBox"); } } void __fastcall TLessListBox::Loaded(void) { TCustomListBox::Loaded(); // call the inherited method /* set up the members which need the window handle of the object */ IntegralHeight = true; Style = lbVirtual; OnData = OnDataHandler; setup_displayed_lines(); OnResize = &OnResizeHandler; // set up the event handler if (!ScrollWidth) { //change only if there is default value ScrollWidth = (int) ((double) def_max_line_len * 1.4L * abs(Font->Height)); } } __fastcall TLessListBox::~TLessListBox() { /* delete buffers */ delete buf1.pList; delete buf2.pList; delete COM_Critical; /* close input file if open */ if (fp) { fclose(fp); } } .... .... .... //--------------------------------------------------------------------------- namespace Tlesslistbox { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TLessListBox)}; RegisterComponents(L"NewComponents", classes, 0); } } |
![]() |
Сообщ.
#4
,
|
|
Я сомневаюсь что в коде ошибка, ибо исключение выдает среда (Билдер) при запуске, а она код не парсает (максимум - только dfm-ки, так что если и причина в коде приложения - то только в dfm-ке(ах)).
Цитата iFinder @ Пробовал положить мою .bpl в директории, где лежат .bpl Builder'a Положить мало, надо еще и перерегистрировать пакет из Билдера указав bpl-ку из нового пути. |
Сообщ.
#5
,
|
|
|
Выявил закономерность: указанная ошибка возникает если компонент был собран в режиме Debug, где бы он не находился и был зарегистрирован.
|