Показать сообщение отдельно
  #7  
Старый 26.05.2025, 01:17
lmikle lmikle вне форума
Модератор
 
Регистрация: 17.04.2008
Сообщения: 8,100
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
По умолчанию

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.
Тут пришлось ширину колонки установить вручную, автоматически не раскрывается на полную.
Ответить с цитированием