자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15912
공지 유용한 관련 사이트 관리자2 2014.03.20 54717
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 98170
34 APP STORE IOS....앱 아이콘을 Xcode의 자산 카탈로그에 추가해야합니다 문제 [1] 성후아빠 2020.07.07 253
33 안드로이드 개발시 IDE 에러 확인 좀 부탁 드립니다. max 2020.08.24 170
32 ios 자신의 전화번호 확인은 불가능한건가요? [3] 델마당쇠 2020.08.25 21132
31 Android permission 루트 data 폴더 접근권한 얻으려면? [2] 델마당쇠 2020.08.31 1053
30 FMX개발시 레이아웃 구성관련 문의 [2] Firemonkey 2020.09.24 385
29 FMX 안드로이드 개발시 폰트리스트 가져오는 방법? Firemonkey 2020.10.13 156
28 안드로이드 개발시 선굵기가 제각기로 나오는 이유(현상) [1] file delphiman 2020.11.17 166
27 폰트 적용 관련 문의 Firemonkey 2020.11.25 140
26 Andorid, IOS에서 동영상 갤러리를 여는 방법 [2] delphiman 2020.11.26 198
25 Andorid, IOS에서 Media (동영상)갤러리를 호출하는 방법 delphiman 2020.12.01 535
24 FMX ICON파일 왜 안되죠? [1] 서준아빠 2020.12.11 281
23 macOS Big Sur 에서 [DCC Error] E2597 Undefined symbols for architecture arm64: 에러 나옵니다. file 텔로스김 2020.12.17 234
22 구글 플레이스토어에 델파이 10.3.3 으로 만든 앱 배포 등록시 오류 밤바야 2020.12.28 173
21 DATASNAP 사용 시 macOS에서 한글깨짐 문제 [1] file 8585 2020.12.29 213
20 모바일에서 이미지 로딩시, 사진 방향이 바뀌는 이유 [3] delphiman 2021.01.26 349
19 linux console에서 webbrowser에러 100jk 2021.02.23 108
18 델파이 10.4.1 환경에서 IOS Device 14.4 디버깅 관련 문의 [2] 2an 2021.02.24 938
17 델파이(10.4.1) ios App 전체화면 안되는 부분 질문드립니다. 쟝히 2021.03.04 869
16 TListBox 내 TListItem 삭제 [2] 공수래 2021.03.10 161
15 IOS 앱 개발 후 배포작업중에 에러를 해결할수없어 질문드립니다.. [2] 밤바야 2021.03.15 595