![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
![]() Здравствуйте.
TListView (и TJvListView) ограничивает длину строки SubItems в 255 символов. Есть ли способ обойти это ограничение? Последний раз редактировалось Dummens, 23.05.2025 в 05:00. |
#2
|
|||
|
|||
![]() А кто тебе сказал, что есть такое ограничение?
Вот простейший пример (см ниже). При нажатии на кнопку 2 я ясно вижу, что все символы на месте (которые после 255). Т.е. это ты что-то напутал. Например, использовал где-то ShortString, вот при приведении типов где-то косяк и всплыл. Код:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls; type TForm1 = class(TForm) ListView1: TListView; Button1: TButton; Button2: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var item : TListItem; i : Integer; s : String; begin s := ''; for I := 1 to 250 do s := s + inttostr(i mod 10); s := s + 'end'; item := ListView1.Items.Add; item.Caption := 'caption ' + s; item.SubItems.Add('subitem 1 ' + s); item.SubItems.Add('subitem 2 ' + s); item.SubItems.Add('subitem 3 ' + s); end; procedure TForm1.Button2Click(Sender: TObject); const separator : String = #13#10 + '#' + #13#10; var s : String; begin if ListView1.Selected <> Nil then begin s := ListView1.Selected.caption + separator + ListView1.Selected.SubItems[0] + separator + ListView1.Selected.SubItems[1] + separator + ListView1.Selected.SubItems[2]; Memo1.Lines.Text := s; end; end; end. |
#3
|
|||
|
|||
![]() Код:
unit Unit1; interface uses //Winapi.Windows, //Winapi.Messages, System.SysUtils, // IntToStr, FreeAndNil Vcl.Controls, // alClient Vcl.Forms, CommCtrl, // for LVSCW_AUTOSIZE ComCtrls; // for TListView type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; ListView1: TListView; ListItem1: TListItem; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin form1.Height := 115; form1.Width := 350; form1.Position := poScreenCenter; form1.Caption := 'Subitems[2] in 255 characters'; ListView1 := TListView.Create(Self); with ListView1 do begin Parent := Self; Align := alClient; ViewStyle := vsReport; BorderWidth := 2; GridLines := true; end; with ListView1.Columns do begin Add.Caption := 'Line № '; Add.Caption := 'Error '; Add.Caption := 'String '; end; try ListView1.Items.BeginUpdate; ListItem1 := ListView1.Items.Add; ListItem1.Caption := '22421 '; ListItem1.SubItems.Add('All Columns ' + IntToStr(ListView1.Columns.Count)); ListItem1.SubItems.Add('<RHINOSTRING English="Exploding this mesh will create %d individual meshes. This may be more than your system can safely manage using the available memory. You can use Weld to make the mesh explode into fewer pieces, or see Help for more information.\n\nClick OK to proceed with Explode, or Cancel to leave the mesh as is.[[24836]]" Localized="Exploding this mesh will create %d individual meshes. This may be more than your system can safely manage using the available memory. You can use Weld to make the mesh explode into fewer pieces, or see Help for more information.\n\nClick OK to proceed with Explode, or Cancel to leave the mesh as is.[[24836]]" />'); //uses CommCtrl; ListView1.Columns[0].Width := {LVSCW_AUTOSIZE or} LVSCW_AUTOSIZE_USEHEADER; ListView1.Columns[1].Width := {LVSCW_AUTOSIZE or} LVSCW_AUTOSIZE_USEHEADER; ListView1.Columns[2].Width := LVSCW_AUTOSIZE {or LVSCW_AUTOSIZE_USEHEADER}; finally ListView1.Items.EndUpdate; end; end; procedure TForm1.FormDestroy(Sender: TObject); begin FreeAndNil(ListView1); end; end. |
#4
|
|||
|
|||
![]() lmikle Модератор <- Вы, юноша, у Михаила Фленова тыкать научились?
Честно говоря, Вам можно поставить неудовлетворительную оценку за ответ. Вопрос не внимательно читаете. Увидеть строку полностью можно не используя редакторы. Например, ShowMessage(ListView1.Items[0].SubItems[1]); Последний раз редактировалось Dummens, 25.05.2025 в 16:49. |
#5
|
|||
|
|||
![]() Ну, во первых, тут на форкмк принято на ты. Так что тут мимо.
С юношей тоже мимо. Теперь по конкретике. Вот как раз в SjowMessage строка и не показывается полностью. А при выводе в Memo я ее полностью вижу. Так что никаких ограничений на длинну строки нет (ну если только Дельфи не древняя, где String = ShortString по умолчанию, было такое в первыз 2х версиях, еслм не ошибаюсь). А конкретная ошибка - литерал не может быть длинее 255 символов. Так что ВАМ кол за вопрос - код не предоставили, ошибку переврали. Проблема не в TListView, а в самой строке. Строковый литерал не может быть длинее 255 символов, т.е. сама строка слишком длинная. Поменял в ВАШЕМ коде одно место и все заработало: Код:
procedure TForm1.FormCreate(Sender: TObject); const sLong = '<RHINOSTRING English="Exploding this mesh will create %d individual meshes. This may be more than your system can safely manage using the '+ 'available memory. You can use Weld to make the mesh explode into fewer pieces, or see Help for more information.\n\nClick OK to proceed with Explode,'+ ' or Cancel to leave the mesh as is.[[24836]]" Localized="Exploding this mesh will create %d individual meshes. This may be more than your system can safely'+ ' manage using the available memory. You can use Weld to make the mesh explode into fewer pieces, or see Help for more information.\n\n'+'Click OK to proceed'+ ' with Explode, or Cancel to leave the mesh as is.[[24836]]" />'; begin ... ListItem1.SubItems.Add(sLong); ... end; |
#6
|
|||
|
|||
![]() Код:
... finally ListView1.Items.EndUpdate; end; ShowMessage(ListView1.Items[0].SubItems[1]); end; Скриншот ShowMessage не прикрепляется... sLong ![]() ![]() По поводу юноши - в точку. Вы ещё молоды - амбиции наружу сами вылазят... ![]() Спасибо за попытку помочь ![]() |
#7
|
|||
|
|||
![]() 1. Константу сделал просто для удобства.
2. Отображение - не проверял, но если колонку сделать нужной ширины, то должно отобразиться все. В хинте обрезается, но это поведение именно родного виндового контрола, TListView - просто обертка над ним. Если и есть какие-то онраничения, то 3. Еще раз - нельзя сделать литерал длинной более 255 символов. Это ограничение компилятора, а не компонента. В последней версии, вроде, сделали длинные литералы, но надо смотреть, у меня не последняя. Фактически, sLong и создает UnicodeString/AnsiString из нескольких литералов. ЗЫ. По поводу возраста и амбиций даже спорить не хочу, все равно объяснять бесполезно. Хотя излишнее использование смайлов уже говорит о том, что я, все-таки, старше. ЗЗЫ. Просьба не указывать на очепятки, у меня клава без русских букв... ЗЗЗЫ. Прекращаем срач. Если еще есть вопросы по существу - задавай, если нет - то лучше вообще не отвечать. Вот твой пример с полной отрисовкой строки: Код:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, CommCtrl, ComCtrls; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure ListView1CustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean); private { Private declarations } public { Public declarations } end; var Form1: TForm1; ListView1: TListView; ListItem1: TListItem; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); const sLong = '<RHINOSTRING English="Exploding this mesh will create %d individual meshes. This may be more than your system can safely manage using the '+ 'available memory. You can use Weld to make the mesh explode into fewer pieces, or see Help for more information.\n\nClick OK to proceed with Explode,'+ ' or Cancel to leave the mesh as is.[[24836]]" Localized="Exploding this mesh will create %d individual meshes. This may be more than your system can safely'+ ' manage using the available memory. You can use Weld to make the mesh explode into fewer pieces, or see Help for more information.\n\n'+'Click OK to proceed'+ ' with Explode, or Cancel to leave the mesh as is.[[24836]]" />'; begin form1.Height := 115; form1.Width := 350; form1.Position := poScreenCenter; form1.Caption := 'Subitems[2] in 255 characters'; ListView1 := TListView.Create(Self); with ListView1 do begin Parent := Self; Align := alClient; ViewStyle := vsReport; BorderWidth := 2; GridLines := true; OnCustomDrawSubitem := ListView1CustomDrawSubItem; end; with ListView1.Columns do begin Add.Caption := 'Line № '; Add.Caption := 'Error '; Add.Caption := 'String '; end; try ListView1.Items.BeginUpdate; ListItem1 := ListView1.Items.Add; ListItem1.Caption := '22421 '; ListItem1.SubItems.Add('All Columns ' + IntToStr(ListView1.Columns.Count)); ListItem1.SubItems.Add(sLong); //uses CommCtrl; ListView1.Columns[0].Width := {LVSCW_AUTOSIZE or} LVSCW_AUTOSIZE_USEHEADER; ListView1.Columns[1].Width := {LVSCW_AUTOSIZE or} LVSCW_AUTOSIZE_USEHEADER; ListView1.Columns[2].Width := ListView1.Canvas.TextWidth(sLong) + 4; finally ListView1.Items.EndUpdate; end; end; procedure TForm1.FormDestroy(Sender: TObject); begin FreeAndNil(ListView1); end; procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean); var rc : TRect; begin DefaultDraw := SubItem <> 2; if Not DefaultDraw then begin ListView_GetSubItemRect(ListView1.Handle, Item.Index, SubItem, LVIR_BOUNDS, @rc); Sender.Canvas.FillRect(rc); Sender.Canvas.TextOut(rc.Left, rc.Top, Item.SubItems[1]); end; end; end. Последний раз редактировалось lmikle, 26.05.2025 в 18:30. |
#8
|
||||
|
||||
![]() Цитата:
Вам видимо 70+ лет и на форуме в первый раз в жизни Тогда понятно ваше старческое брюзжание И не стоит писать с умным видом всякую чушь, что тот же ListView ограничивает длину строки, как и хамить модераторам. А если только что купили книжку по программированию, то ведите себя соответствующе вашим нулевым знаниям. |
#9
|
|||
|
|||
![]() А разве с Delphi работают не только 70-ти летние?
![]() |