I just did that for a project right now. I don't know what are your
skills with classes... But here are some clues. I could send you much
more detailed sources by private mail if you really need so. (This is
not tested, I wrote directly in the email.) Some parts are missing,
but you get the idea.

type

TMyGrid = class
private
 FRow: array of array string;
 function GetValue(const x, y: Integer): string;
 procedure SetValue(const x, y: Integer; const s: string);
public
 procedure Add(const x, y: Integer; const s: string);
 property Values[const x, y: Integer]: string read GetValue write
SetValue default;
end;

implementation

function TMyGrid.GetValue(const x, y: Integer): string;
begin
 //example of range check:
 if (x < 0) or (x > High(FRow)) or
    (y < 0) or (y > High(FRow[x])) then
   raise Exception.Create('Index OutOfRange ['+IntToStr(x)+','+IntToStr(y)+']')
 else
   Results := FRow[x, y];
end;

procedure TMyGrid.SetValue(const x, y: Integer; const s: string);
begin
 //example of range check:
 if (x < 0) or (x > High(FRow)) or
    (y < 0) or (y > High(FRow[x])) then
   raise Exception.Create('Index OutOfRange ['+IntToStr(x)+','+IntToStr(y)+']')
 else
   FRow[x, y] := s;
end;

procedure TMyGrid.Add(const x, y: Integer; const s: string);
begin
 //0,0 is the first element
 //you should optimize to increase array in batch, not each time you
add an element
 if x < High(x) then
   SetLength(FRow, x+1);
 if y < (High(FRow[x])) then
   SetLength(FRow[High(x)], y+1);
 FRow[x, y] := s;
end;

Again, I just did not test all that. Might work or not out of the box.
But you get all the principles to do what you need :)

Hope this helps.

2006/7/18, bobby <[EMAIL PROTECTED]>:
I need a class that will be compatible with StringGrid in the meaning of
content (Rows, Columns, Cells properties).
The problem is that I don't know how to write a class, and I would ask
if someone can point me to some good reading.

Why?
I have a program that I would like to optimize a bit. The problem is
that the program writes a lot of data to StringGrid cells in a loop.
The idea is to have a non-visual grid (I hope it will be faster than
StrinGrid), and to copy its content to StringGrid after finishing the loop.

--
Alexandre Leclerc

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to