Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: FMX TStringGrid Anzeigefehler ?!?!

  Alt 23. Dez 2012, 23:21
Jo, bei FMX gibt es da so einige kleinere Bugs

Auch das Aktualisieren der Anzeige in einem Grid gehört dazu.
Dieses muss zeitweilig manuell nochmal angestossen werden.

Hier mal eine Unit, womit man die Zellen in einem Grid aktualisieren lassen kann.

Der Aufruf erfolgt dann ganz banal mit TGridTools.UpdateCells( MyStringGrid ); und es werden alle sichtbaren Zellen aktualisiert.

Pauschal kann man diesen Aufruf in einen Idle-Event packen (TApplicationEvents.OnIdle) oder eben an die diversen Methoden des Grids hängen.

Delphi-Quellcode:
unit FMX.CommonGuiTools;

interface

uses
  FMX.Grid, FMX.Forms;

type
  TGridTools = class abstract
    class procedure UpdateCells( const AGrid : TGrid; const Visible : Boolean = True ); overload;
    class procedure UpdateCells( const AGrid : TGrid; const AMethod : TOnGetValue;
      const VisibleRows : Boolean = True ); overload;
    class procedure AutosizeColumn( const AGrid : TGrid; const ColumnIndex : Integer; const MinWidth : Single = 0 );
  end;

  TFormTools = class abstract
    class procedure CenterForm( const AForm, BForm : TCommonCustomForm );
  end;

implementation

uses
  System.Math;

{$IF CompilerVersion = 23}

type
  THackedColumn = class( TColumn )
  end;
{$IFEND}
  { TGridTools }

class procedure TGridTools.AutosizeColumn( const AGrid : TGrid; const ColumnIndex : Integer; const MinWidth : Single );
var
  LCol : Integer;
  LWidth : Single;
  LClientWidth : Single;
begin

  LWidth := 0;
  for LCol := 0 to Pred( AGrid.ColumnCount ) do
    begin
      if ( LCol <> ColumnIndex ) and AGrid.ColumnByIndex( LCol ).Visible
      then
        LWidth := LWidth + AGrid.ColumnByIndex( LCol ).Width;
    end;

  repeat
    LClientWidth := AGrid.ClientWidth;
    AGrid.ColumnByIndex( ColumnIndex ).Width := Max( MinWidth, AGrid.ClientWidth - LWidth );
  until SameValue( LClientWidth, AGrid.ClientWidth, 0.0001 );
end;

class procedure TGridTools.UpdateCells( const AGrid : TGrid; const Visible : Boolean );
var
  LCol, LRow, LRowMin, LRowMax : Integer;
  LColumn : TColumn;
begin
  if Visible
  then
    begin
      LRowMin := AGrid.TopRow;
      LRowMax := Pred( Min( AGrid.TopRow + AGrid.VisibleRows, AGrid.RowCount ) );
    end
  else
    begin
      LRowMin := 0;
      LRowMax := Pred( AGrid.RowCount );
    end;

  for LCol := 0 to Pred( AGrid.ColumnCount ) do
    begin
      LColumn := AGrid.ColumnByIndex( LCol );

{$IF CompilerVersion = 23}
      THackedColumn( LColumn ).UpdateColumn;
{$ELSE}
      for LRow := LRowMin to LRowMax do
        if ( Visible and AGrid.ColumnByIndex( LCol ).Visible ) or not Visible
        then
          LColumn.UpdateCell( LRow );
{$IFEND}
    end;
end;

class procedure TGridTools.UpdateCells( const AGrid : TGrid; const AMethod : TOnGetValue; const VisibleRows : Boolean );
var
  LMethod : TOnGetValue;
begin
  LMethod := AGrid.OnGetValue;
  try
    AGrid.OnGetValue := AMethod;
    UpdateCells( AGrid, VisibleRows );
  finally
    AGrid.OnGetValue := LMethod;
  end;
end;

{ TFormTools }

class procedure TFormTools.CenterForm( const AForm, BForm : TCommonCustomForm );
begin
  AForm.Left := BForm.Width div 2 + BForm.Left - AForm.Width div 2;
  AForm.Top := BForm.Height div 2 + BForm.Top - AForm.Height div 2;
end;

end.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo (24. Dez 2012 um 08:15 Uhr)
  Mit Zitat antworten Zitat