Page 1 of 1

TStringGrid with Width property > 32768 (impossible)

PostPosted: July 12th, 2011, 11:19 am
by Tisseyre
With delphi 5 if i use a TStringGrid , i can't have a width property > 32768 px !
Do you know why ? :?:
the width property is integer but < 32768 !
you can try with this code but before you must use this component :


Code: Select all
  type TRicScrollBox = class(TScrollBox)
      private
             FOnHorizontalScroll: TNotifyEvent;
             procedure WMHScroll(var Messag: TWMHScroll); message WM_HSCROLL;
      public
            constructor Create(AOwner: TComponent); override;
            Destructor Destroy; Override;
      published
               property OnHorizontalScroll: TNotifyEvent read FOnHorizontalScroll write FOnHorizontalScroll;
      end;

      procedure Register;

      implementation

      constructor TRicScrollBox.Create(AOwner: TComponent);
      begin
      inherited Create(AOwner);
      end;

      destructor TRicScrollBox.Destroy;
      begin
      Inherited Destroy;
      end;

      procedure TRicScrollBox.WMHScroll(var Messag: TWMHScroll);
                begin
                inherited;
                if Assigned(FOnHorizontalScroll) then FOnHorizontalScroll(Self);
                end;

      procedure Register;
      begin
      RegisterComponents('MyDelphi', [TRicScrollBox]);
      end;

    end.
   


This is an example :

Code: Select all
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, UnitRicScrollBox;

type
  TForm1 = class(TForm)
    RicScrollBox1: TRicScrollBox;
    StringGrid1: TStringGrid;
    procedure StringGrid1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.StringGrid1Click(Sender: TObject);
  var i : integer;
begin
  StringGrid1.width := StringGrid1.width *2;
  StringGrid1.colcount := StringGrid1.colcount*2;
  for i := 1 to StringGrid1.colcount do StringGrid1.Cells[i-1,0] := inttostr(i);
  ricscrollbox1.repaint;
  Caption := 'Colcount = '+ inttostr(StringGrid1.colcount) + ' / grid.Width = '+inttostr(StringGrid1.width);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  form1.width := 550;
  with Ricscrollbox1 do
       begin
       align := alclient;
       Autoscroll := true;
       Autosize := false;
       end;
  with StringGrid1 do
       begin
       width := clientWidth;
       Height := ClientHeight;
       rowcount := 1;
       colcount := 5;
       defaultcolwidth := width div 5;
       defaultRowHeight := height div 2;
       end;
  StringGrid1Click(Self);
end;

end.

Re: TStringGrid with Width property > 32768 (impossible)

PostPosted: July 13th, 2011, 9:29 pm
by Kambiz
It is because TGrid and some other Delphi standard controls use still the old 16bit Windows API.

This old API supports only 16-bit signed integer for scroll position and because of that you cannot scroll more than 32768 pixels.

I wonder how the next version of Delphi is going to be 64bit while it doesn't fully support 32bit Windows yet.

Re: TStringGrid with Width property > 32768 (impossible)

PostPosted: July 14th, 2011, 11:01 am
by Tisseyre
thank you very much for that answer substantiated.
:arrow:
may be I can find on the web (as a component TGrid) but built around a 32-bit architecture?
:cf:

Re: TStringGrid with Width property > 32768 (impossible)

PostPosted: July 15th, 2011, 5:13 am
by mathgod
Hello Tesseyre,

I recently needed a better StringGrid component and found NiceGrid. The project seems to have been abandoned since 2007. You may need to modify the dpk file to get it to install the way you want. I installed the component on Delphi XE and it works fine. Do note, however, that this component is not derived from StringGrid and existing code that uses the native StringGrid component may break after replacing StringGrid. The row object does not seem to be developed so row exchange in a sorting algorithm will have to be done for each cell. To save the contents to a csv file, you will need to create two StringList objects -- one for adding cell contents of a row to a String List and the other for adding the CommaText of each row after the String List is built.

If someone improves the component and shares it, I would like to have the row object developed and perhaps some sorting methods (bubble sort, quick sort, and merge sort) implemented.