TStringGrid with Width property > 32768 (impossible)

Please discuss general Delphi programming topics here.

TStringGrid with Width property > 32768 (impossible)

Postby Tisseyre » July 12th, 2011, 11:19 am

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.
Tisseyre
Active Member
Active Member
 
Posts: 10
Joined: November 23rd, 2010, 10:36 am

Re: TStringGrid with Width property > 32768 (impossible)

Postby Kambiz » July 13th, 2011, 9:29 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: TStringGrid with Width property > 32768 (impossible)

Postby Tisseyre » July 14th, 2011, 11:01 am

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:
Tisseyre
Active Member
Active Member
 
Posts: 10
Joined: November 23rd, 2010, 10:36 am

Re: TStringGrid with Width property > 32768 (impossible)

Postby mathgod » July 15th, 2011, 5:13 am

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.
User avatar
mathgod
Junior Member
Junior Member
 
Posts: 35
Joined: December 15th, 2007, 4:36 pm
Location: Middle of New Mexico, USA


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron