program Project3;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,System.Classes,Contnrs;
type
TGridColumn =
class(Tobject)
private
FWidth: Integer;
FHeight: Integer;
public
constructor Create;
property Width: Integer
read FWidth
write FWidth;
property Height: Integer
read FHeight
write FHeight;
end;
TCustomGrid =
class(TObject)
private
FCols: Integer;
FRows: Integer;
FRowsContainer: TObjectList;
procedure SetCols(AValue: Integer);
procedure SetRows(AValue: Integer);
public
constructor Create;
destructor Destroy;
override;
procedure Paint;
property Cols: Integer
read FCols
write SetCols;
property Rows: Integer
read FRows
write SetRows;
end;
{ TGridColumn }
constructor TGridColumn.Create;
begin
inherited Create;
end;
{ TCustomGrid }
constructor TCustomGrid.Create;
begin
inherited Create;
FRowsContainer := TObjectList.Create;
end;
destructor TCustomGrid.Destroy;
begin
FRowsContainer.Free;
inherited;
end;
procedure TCustomGrid.SetCols(AValue: Integer);
var ACol,ARow: Integer; gridColumn: TGridColumn;
begin
if FCols=AValue
then Exit;
FCols:=AValue;
for ARow := 0
to FRows -1
do
begin
for ACol := 0
to FCols-1
do
begin
gridColumn := TGridColumn.Create;
gridColumn.Width := 200;
gridColumn.Height := 20;
TStringList(FRowsContainer.Items[ARow]).AddObject('
', gridColumn);
if ACol >= FCols-1
then break;
end;
end;
end;
procedure TCustomGrid.SetRows(AValue: Integer);
var ARow: Integer; AList: TStringList;
begin
if FRows=AValue
then Exit;
FRows:=AValue;
for ARow := 0
to FRows-1
do
begin
AList := TStringList.Create; AList.Capacity := 5;
AList.Duplicates:=dupAccept;
FRowsContainer.Add(AList);
end;
end;
procedure TCustomGrid.Paint;
var ACol,ARow,w,h,l,t,r,b: Integer; gc: TGridColumn; sl: TStringList; rc: TObjectList;
begin
for ARow:=0
to FRowsContainer.Count-1
do
begin
for ACol:=0
to TStringList(FRowsContainer.Items[ARow]).Count-1
do
begin
rc := FRowsContainer;
sl := TStringList(rc.Items[ARow]);
gc := TGridColumn(sl.Objects[ACol]);
if (ACol<TStringList(FRowsContainer.Items[ARow]).Capacity)
and Assigned(gc)
then
begin
w := gc.Width;
//TGridColumn(TStringList(FRowsContainer.Items[ARow]).Objects[ACol]).Width;
h := gc.Height;
//TGridColumn(TStringList(FRowsContainer.Items[ARow]).Objects[ACol]).Height;
// l := gc.Left; //TGridColumn(TStringList(FRowsContainer.Items[ARow]).Objects[ACol]).Left; //aus Originalcode übernommen
// t := gc.Top; //TGridColumn(TStringList(FRowsContainer.Items[ARow]).Objects[ACol]).Top; //aber hier weggelassen
end;
// DrawRectangleClip(vscreen,l,t,l+w,t+h,ToColor(colBlack));
writeln('
Breite: ',w);
//wird nicht angezeigt, warum?
writeln('
Höhe : ',h);
//wird nicht angezeigt, warum?
//writeln('Links : ',l);
//writeln('Oben : ',t);
{
t := t + h; //t (Top soll um h (Zeilenhöhe) nach unten, nachdem Gridrahmenlinie oben gezeichnet ist
l := l + w; //l (Left) soll um w (Spaltenbreite) nach rechts, nachdem Gridrahmenlinie links gezeichnet ist
}
inc(t, h);
inc(l, w);
end;
if ARow >= FRows
then break;
end;
end;
var
Grid: TCustomGrid;
begin
try
{ TODO -oUser -cConsole Main : Code hier einfügen }
Grid:=TCustomGrid.Create;
Grid.Cols := 9;
Grid.Rows := 5;
Grid.Paint;
writeln('
Zurück mit << ENTER >> > >>> ... ');
readln;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
end.