Советы по Delphi

         

Производная TOutlineЯ пытаюсь


Если установлен стиль otOwnerDraw, вы можете сами отрисовывать компонент. В этом режиме вы можете вывести какие угодно изображения. Примечание: чтобы получить OwnerDraw для работы, вы должны установить свойство Scrollbar в vsVertical.

Затем обрабатывайте событие OnDrawItem для рисования каждой строчки OutLine.

Для получения правильного индекса узла используйте GetItem(Rect.Left, Rect.Top). Индекс в drawItem неверен.

Вот пример из моего приложения. Надеюсь это вам поможет.

procedure TfrmMain.Outline2DrawItem(Control: TWinControl; Index: Integer;Rect: TRect; State: TOwnerDrawState);var Node: TOutlineNode;NodeIdx: Integer;Offset: Integer;NowBitmap: TBitmap;NowAstValue: String;beginNodeIdx := Outline2.GetItem(Rect.Left, Rect.Top);Node := Outline2.Items[NodeIdx];NowAstValue := PAstRec(Outline2.Items[NodeIdx].Data)^.AstValue;with Outline2.Canvas do beginFont.Name := 'MS Sans Serif';Font.Size := 8;Offset := MulDiv(Font.Size, 150, 100);fillRect(Rect);Rect.Left := Rect.Left + ((Node.Level - 1) * Offset + 2);if Node.HasItems thenbeginif Node.Expanded thenNowBitmap := Outline2.PictureMinuselseNowBitmap := Outline2.PicturePlus;{рисуем иконку}BrushCopy(Rect, NowBitmap,Bounds(0,0, Rect.Right - Rect.Left, Rect.Bottom -Rect.Top),NowBitmap.TransparentColor);end;Rect.Left := Rect.Left + Offset + 2;{выводим текст}TextOut(Rect.left, Rect.Top, Node.Text);{создаем суммирующую колонку с правым выравниванием}Rect.Left := Rect.Right - TextWidth(NowAstValue)- 2;TextOut(Rect.Left, Rect.Top, NowAstValue);end;

-Craig Osterloh

А как работает функция PAstRec() и как получить указатель на данные?

Вот код:

function TfrmMain.LoadAssetNodes(fName: String; header: String): Double;var headerIdx: Integer;NowClientID: String;TotAssetValue: Double;AstRecPtr: PAstRec;sqlText: String;HeadPtr: PAstRec;beginwith qryAssets do beginNowClientID := dtbClients.Fields[0].AsString;sqlText := 'Select * from ' + fName + ' where ClientID = ' +NowClientID;SQL.Clear;SQL.Add(sqlText);Open;First;TotAssetValue := 0;new(HeadPtr);headerIdx := outAssets.AddObject(0, header, HeadPtr);while not EOF do beginnew(AstRecPtr);AstRecPtr^.AstValue := format('%8.0n',[FieldByName('AssetValue').AsFloat]);TotAssetValue :=TotAssetValue + FieldByName('AssetValue').AsFloat;outAssets.AddChildObject(headerIdx,FieldByName('AssetName').AsString,AstRecPtr);Next;end;HeadPtr^.AstValue := format('%8.0n',[TotAssetValue]);Result := TotAssetValue;end;end;

-Craig Osterloh[000475]



Содержание раздела