자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 Q&A 이용 (제품 구매 고객 한정)

FM에서 DB올리고 Live Binding으로 String Grid에 뿌렸을데

Grid의 타이틀을 멀티(2줄3줄)로 사용할려고 하는데 어떻게 해야 하는지 난감하네요.

Headerd에 접근이 않되는 것인지? 알려 주세요

 

아래 소스는 VCL의 DBGrid의 Title을 2줄또는 그 이상으로 멀티로 하는 소스인데

이것을 FM에 적용해 보니 에러 떨어지는데 소스라도 좀 FM에 맞게 수정 좀 부탁 합니다.

 

 

 

unit MLDBGrid;


interface

uses Windows, Classes, SysUtils, Controls, Graphics, DBGrids, Db, Grids;

type
  TMultiLineGrid = class(TDBGrid)
    private
      FTitleHeight: Integer;
    protected
      procedure LayoutChanged; override;
      procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
      procedure SetTitleHeight(Value: Integer);
    public
      constructor Create(AOwner: TComponent); override;
      property Row;
      property Col;
    published
      property TitleHeight: Integer read FTitleHeight write SetTitleHeight;
      property OnMouseMove;
  end;

procedure Register;

implementation

constructor TMultiLineGrid.Create(AOwner: TComponent);
begin
  inherited;
  FTitleHeight:=17;
end;

procedure TMultiLineGrid.SetTitleHeight(Value: Integer);
begin
  if FTitleHeight<>Value then
  begin
    FTitleHeight:=Value;
    LayoutChanged;
  end;
end;

procedure TMultiLineGrid.LayoutChanged;
begin
  inherited;
  if dgTitles in Options then RowHeights[0]:=FTitleHeight;
end;

function BreakStr(ACanvas: TCanvas; StrWidth: Integer; Str: String): TStringList;
const Dividers=' ,.<>:;-*/+"''$#()=';
var i: Integer;
    tmp: String;
    Words: TStringList;
begin
  Words:=TStringList.Create;
  Result:=TStringList.Create;
  tmp:='';
  for i:=1 to Length(Str) do
  begin
    tmp:=tmp+Str[i];
    if Pos(Str[i],Dividers)>0 then begin Words.Add(tmp); tmp:='' end;
  end;
  Words.Add(tmp);
  tmp:='';
  Result.Add(Words[0]);
  for i:=1 to Words.Count-1 do
  begin
    if (ACanvas.TextWidth(Result[Result.Count-1]+Words[i])>StrWidth) then
    begin
      Result[Result.Count-1]:=Trim(Result[Result.Count-1]); //trim the blanks at the line's edges
      Result.Add(Words[i]);
    end
    else
      Result[Result.Count-1]:=Result[Result.Count-1]+Words[i];
  end;
  Words.Free;
end;

procedure TMultiLineGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var
    MasterCol,Column: TColumn;
    TitleRect: TRect;
    LeftPoint,i, LineHeight: Integer;
    Strs: TStringList;
begin
  if (dgTitles in Options) and (ARow=0) and ((ACol>0) or (not (dgIndicator in Options))) then
  begin
    if dgIndicator in Options then Column:=Columns[ACol-1] else Column:=Columns[ACol];
    TitleRect:=CalcTitleRect(Column, ARow, MasterCol);
    if MasterCol = nil then
    begin
      Canvas.Brush.Color := FixedColor;
      Canvas.FillRect(ARect);
      Exit;
    end;
    Canvas.Font := MasterCol.Title.Font;
    Canvas.Brush.Color := MasterCol.Title.Color;
    Canvas.FillRect(TitleRect);
    Strs:=BreakStr(Canvas,ARect.Right-ARect.Left-4,MasterCol.Title.Caption);
    LineHeight:=Canvas.TextHeight('Wg');
//    Strs:=BreakStr(Canvas,ARect.Right-ARect.Left-4,'asdfgad adsfgdffff gfdfg dfgdfgdg');
    for i:=0 to Strs.Count-1 do
    begin
      case Column.Title.Alignment of
        taLeftJustify:
          LeftPoint:=ARect.Left+2;
        taRightJustify:
          LeftPoint:=ARect.Right-Canvas.TextWidth(Strs[i])-3;
        taCenter:
          LeftPoint:=ARect.Left+(ARect.Right-ARect.Left) shr 1 - (Canvas.TextWidth(Strs[i]) shr 1);
      else
        LeftPoint:=0;
      end;
      Canvas.TextRect(ARect,LeftPoint,ARect.Top+2,Strs[i]);
      ARect.Top:=ARect.Top+LineHeight+2;
    end;
    Strs.Free;
    if [dgRowLines, dgColLines]*Options=[dgRowLines, dgColLines] then
    begin
      DrawEdge(Canvas.Handle, TitleRect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
      DrawEdge(Canvas.Handle, TitleRect, BDR_RAISEDINNER, BF_TOPLEFT);
    end;
  end
  else inherited;
end;

procedure Register;
begin
  RegisterComponents('Data Controls', [TMultilineGrid]);
end;

end.
번호 제목 글쓴이 날짜 조회 수
공지 [프로그래밍 강의] 2021.6~2021.12 관리자 2015.01.22 15766
공지 유용한 관련 사이트 관리자2 2014.03.20 54580
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 97983
94 XE6 TMemo 키보드 이벤트 문제 가을이다 2014.07.03 2320
93 XE6 앱개발 기본 에디트박스 스타일없애기 [1] 가을이다 2014.07.01 2426
92 스크롤박스 버벅현상 개선방법 [3] 가을이다 2014.06.28 2507
91 데이터 스냅 모바일 적용시 오류 초보델파이 2014.07.01 2151
90 xe6 firemonkey tabcontrol 에서 tabitem height 사이즈 변경이 불가능 합니다.. [2] 프리스켄 2014.06.28 2717
89 안드로이드에서 MS-SQL 접속 방법 [4] Humphery 2014.06.25 8240
88 XE6 Label 폰트컬러 변경 문의 [2] file 가을이다 2014.06.23 2005
87 XE5 ISO 개발 옵션 문의 [1] file 햇반 2014.06.20 1814
86 XE5 스크롤시 버벅현상 [1] 가을이다 2014.06.20 2115
85 스크롤시 끊김 현상 [1] 가을이다 2014.06.16 3034
84 XE5 FireMonkey 버튼 컴포넌트 만들기.. [1] file 가을이다 2014.06.16 2418
83 구현 방법 문의 ( ListBox or ListView ) [3] 계양전기 2014.05.29 3153
82 이미지 선택영역 표시하기.. [2] 가을이다 2014.06.14 2481
81 XE5 안드로이드 TTS 사용하기 [1] 가을이다 2014.06.08 3132
80 XE5 스크롤박스 사용시 컴포넌트 드래그시 스크롤 미동작. [2] 가을이다 2014.06.14 2372
79 Rectangle 컬러값 변경 문의 [2] 가을이다 2014.06.13 2637
78 [세미나] 스플래쉬 추가후 일부 구동시 문제가 발생합니다. [1] Humphery 2014.06.12 2050
77 [세미나] 메시지 다이얼로그 표시된 상태에서 절전모드 이후 먹통이 됩니다. [1] Humphery 2014.06.12 2585
76 [세미나] 네이티브코드로 개발된 모바일 버전과 파일사이즈가 차이가 납니다. [1] Humphery 2014.06.12 2084
75 [세미나] 모바일에서 새로운 OS버전이 나오면 어떻게 하나요? [1] Humphery 2014.06.12 2041