자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15802
공지 유용한 관련 사이트 관리자2 2014.03.20 54604
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 98039
179 BPL 컴파일 결과에 대한 문의입니다. CCS 2012.12.04 7544
178 Access violation 버그 Feelple(고재철) 2012.10.29 7558
177 갤럭시 탭 가로모드 실행시, 앱이 꺼지는 현상 [3] 가을이다 2016.12.07 7561
176 파이어몽키에서 Application.processMessage 사용.... Happycube 2012.10.17 7568
175 DBExpess 예제관련 문의 [1] ideveloper 2012.11.26 7581
174 TeeChart v2013 VCL/FMX 구입하면 XE5에서 호환될까요? [1] 딸기 2013.09.11 7582
173 Excel Component 문의 [1] ideveloper 2012.11.28 7600
172 파이어몽키 어플리케이션 폼에 컴포넌트를 올려놓아도 아무것도 안보입니다. file 하두고 2012.07.04 7624
171 XE5 안드로이드 관련 추가적으로 필요한 사항 [1] c2design 2013.09.23 7627
170 델파이7과 그 이상 버전의 string의 처리에 대한 질문 [1] couping 2013.05.10 7637
169 델파이XE5에서 안드로이드 SDK 관리자가 실행이 안됩니다. [1] 관리자 2013.10.08 7693
168 2월 29일 데이터스냅 강의 자료는 어디있나요? [1] nomad 2012.03.06 7700
167 BOGO 프로모션 툴 다운로드 받는 방법 안내(2015.6.1~2015.6.30 구매고객) 관리자 2014.06.16 7704
166 파이어몽키 3D 폼에서 컴포넌트 안보이는 문제 [1] cdrd 2012.09.13 7713
» FM의 Grid의 타이틀을 멀티로 사용할려면? memc 2013.03.06 7713
164 RAD, 델파이, C++빌더의 에디션별 업그레이드 적용 범위를 알고 싶습니다. 관리자 2012.07.19 7717
163 Begin-end 16장 한글깨짐 현상에 대한 질문 file funny 2013.01.28 7734
162 통화목록 관련 [1] 100jk 2021.05.14 7760
161 class TAdvGridWorkbook not found 경우는 어떤 방법이 있나요? [1] 으하하 2013.11.01 7769
160 지난번 세미나 자료 좀 구할 수 있을까요 ? [1] 준이킴 2012.05.03 7781