![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
опять Access vialation......................... :(
Dust © (2006-03-20 12:05:00)После строчки выделенной жирным при работе с любыми строками или функциями происходит Aхтунг. Как быть? Что я делаю не правильно?
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
var ListBox : TListBox;
tmp_str : string;
count_chars : Integer;
res : LongBool;
Int1p, Int2p : Integer;
tgSIZE : tagSIZE;
pch1 : Pchar;
begin
ListBox := Control as TListBox;
tmp_str := ListBox.Items[Index];
tgSIZE.cx := ListBox.Width;
tgSIZE.cy := ListBox.ItemHeight;
pch1 := StrAlloc (length(tmp_str));
StrPCopy(pch1, tmp_str);
res := GetTextExtentExPoint (ListBox.Canvas.Handle, pch1, length(tmp_str), ListBox.Width, @Int1p, @Int2p, tgSIZE);
if not res then
ShowMessage (SysErrorMessage(GetLastError));
.......................
Плохиш (2006-03-20 12:53:00) [1]
pch1 := StrAlloc (length(tmp_str) +1 );
StrPCopy(pch1, tmp_str);
Dust (2006-03-20 12:51:00) [2]Вопрос закрыт
Dust (2006-03-20 12:50:00) [3]Вот так работает:
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
var ListBox : TListBox;
tmp_str : string;
str_ln : Integer;
count_chars : Integer;
res : LongBool;
Int1p : Integer;
pInt2 : array of Integer;
tgSIZE : tagSIZE;
begin
ListBox := Control as TListBox;
tmp_str := ListBox.Items[Index];
str_ln := Length (tmp_str);
tgSIZE.cx := 0; //ListBox.ClientWidth;
tgSIZE.cy := 0; //ListBox.ItemHeight;
SetLength (pInt2, str_ln);
res := GetTextExtentExPoint (ListBox.Canvas.Handle, Pchar(tmp_str), str_ln, ListBox.ClientWidth, @Int1p, @pInt2[0], tgSIZE);
if not res then
ShowMessage (SysErrorMessage(GetLastError));
............
wicked (2006-03-20 12:47:00) [4]> Dust © (20.03.06 12:41) [5]
> нет, только предпоследний параметр
> LPINT alpDx, // array of partial string widths
пардон, невнимательно прочел....
Dust (2006-03-20 12:41:00) [5]нет, только предпоследний параметр
LPINT alpDx, // array of partial string widths
wicked (2006-03-20 12:16:00) [6]хм.... прочел msdn, советую прочитать также........ насчет адресов я ошибся, признаю.......
итак, даю 99% и зуб в придачу, что AV валятся из-за того, что 3-й и 2-й параметры с конца передаются неправильно..... правильно было бы создать 2 динамических массива, сделать обоим SetLength(<массив>, length(tmp_str)) и передавать в функцию их как @(<массив>[0]).....
Dust (2006-03-20 12:11:00) [7]wicked,
за совет спасибо, учту
wicked (2006-03-20 12:09:00) [8]
> pch1 := StrAlloc (length(tmp_str));
> StrPCopy(pch1, tmp_str);
это зачем?.... можно просто написать PChar(tmp_str).......
и рекомендую посмотреть на прототип обьявления GetTextExtentExPoint - скорей всего там параметры обьявлены через var, так что не нужно явно передавать их адреса....
> tgSIZE.cx := ListBox.Width;
лучше заменить на
tgSIZE.cx := ListBox.ClientWidth;
для учета того, что когда то в этом листбоксе и скроллер появится....
Dust (2006-03-20 12:09:00) [9]Эта дрянная функция возвращает True даже если написать вот так!
res := GetTextExtentExPoint (0, nil , 0, ListBox.Width, @Int1p, @Int2p, tgSIZE);
Это глюк? или фича??