자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15634
공지 유용한 관련 사이트 관리자2 2014.03.20 54464
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 97828
94 Android Virtual Devices Manager에서 Device를 추가할수가 없습니다.. [1] file 김동환 2014.07.24 2541
93 [세미나] 메시지 다이얼로그 표시된 상태에서 절전모드 이후 먹통이 됩니다. [1] Humphery 2014.06.12 2584
92 FMX 동적생성 버튼 폰트, 크기 변경 방법 [3] superman 2014.08.20 2624
91 Rectangle 컬러값 변경 문의 [2] 가을이다 2014.06.13 2631
90 XE6 TWebBrowser 종료안됨 현상 [2] 가을이다 2014.07.04 2642
89 xe6 firemonkey tabcontrol 에서 tabitem height 사이즈 변경이 불가능 합니다.. [2] 프리스켄 2014.06.28 2716
88 [세미나] TWebBrowser Component 사용시 JavaScript 기능을 사용할 수 있나요? [4] Humphery 2014.06.12 2741
87 안드로이드 서비스(백그라운드 실행)에서 특정 상황에서 앱자동 실행 [2] 김태윤 2016.05.24 2823
86 오늘날짜 표시 [4] fromstog 2014.04.04 2884
85 델파이 xe5 - 안드로이드 - datasnap 개발시 [1] superman 2014.05.07 2922
84 파이어몽키 모바일어플리케이션에서 가상키보드에 의한 화면가림현상 해결좀 [2] 농가사랑 2014.08.29 2964
83 XE5 로 ipa는 못만드나요? [1] 데니얼27 2014.03.19 2987
82 모바일 개발시 이미지 버튼 처리는 어떻게 하나요? [1] couping 2014.03.18 3014
81 스크롤시 끊김 현상 [1] 가을이다 2014.06.16 3027
80 XE6 안드로이드 앱 프로젝트에서 deploy 관리자에서 설정파일 추가후, 파일참조경로를 못찾네요 heiman 2014.07.12 3042
79 안드로이드에서 다른 응용프로그램 알림 메세지 정보를 전달 받을수 있나요? 델마당쇠 2020.03.14 3046
78 모바일 폼 구성시 여러개 폼 생성 방법 [6] 수강생 2014.04.28 3066
77 ListBox 테스트시 문의 ( 속도 ) [1] 수강생 2014.04.30 3084
76 XE5 안드로이드 TTS 사용하기 [1] 가을이다 2014.06.08 3130
75 구현 방법 문의 ( ListBox or ListView ) [3] 계양전기 2014.05.29 3153