type TArray = class private FMark : array[0..19] of integer; FCount : integer; FSize : integer; public constructor Create; procedure SetValue(ind, value : integer); function GetValue(ind : integer) : integer; procedure SetArray(a : TArray); procedure Clear; procedure Add(a : integer); property Count : integer read FCount write FCount; property Size : integer read FSize write FSize; end; TMarkTable = class(TStringGrid) private FFio : TStrings; FMark : TArray; protected procedure SetFio(value : TStrings); procedure SetMark(value : TArray); function SelectCell(ACol, ARow : Longint) : boolean; override; procedure DrawCell(ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); override; public constructor Create(AOwner : TComponent); override; procedure MoveData(); destructor Destroy(); override; published property Fio : TStrings read FFio write SetFio stored True; property Mark : TArray read FMark write SetMark; end; procedure Register; implementation uses Math; procedure Register; begin RegisterComponents('Samples', [TMarkTable]); end; constructor TMarkTable.Create(AOwner : TComponent); begin FFio := TStringList.Create; FMark := TArray.Create; inherited Create(AOwner); ColCount := 2; RowCount := 2; FixedCols := 0; FixedRows := 1; Cells[0,0] := 'Ôàìèëèÿ'; Cells[1,0] := 'Áàëë'; end; destructor TMarkTable.Destroy(); begin FFio.Free; FMark.Free; inherited Destroy; end; procedure TMarkTable.SetMark(value : TArray); begin FMark.SetArray(value); end; procedure TMarkTable.SetFio(value : TStrings); begin FFio.Assign(value); MoveData; end; procedure TMarkTable.MoveData(); var i : integer; begin RowCount := Max(Fio.Count, Mark.Size) + 1; for i:=0 to FFio.Count-1 do Cells[0,i+1] := Fio.Strings[i]; for i:=0 to FMark.Size-1 do Cells[1,i+1] := IntToStr(Mark.GetValue(i)); end; constructor TArray.Create; begin inherited Create; Count := 20; Size := 0; end; procedure TArray.SetValue(ind, value : integer); begin FMark[ind] := value; end; function TArray.GetValue(ind : integer) : integer; begin result := FMark[ind]; end; procedure TArray.Clear; begin FSize := 0; end; procedure TArray.Add(a : integer); begin FMark[FSize] := a; inc(FSize); end; procedure TArray.SetArray(a : TArray); var i : integer; begin Clear; for i := 0 to a.FSize - 1 do Add(a.GetValue(i)); end; function TMarkTable.SelectCell(ACol, ARow : Longint) : boolean; begin InvalidateGrid; result := true; end; procedure TMarkTable.DrawCell(ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin inherited; if gdFocused in State then begin Canvas.Font.Color := RGB(238,43,67); Canvas.Font.Style := [fsBold]; Canvas.Brush.Color := RGB(223,185,133); Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left, Rect.Top, AnsiUpperCase(Cells[ACol,ARow])); end else if not (gdFixed in State) then begin Canvas.Font.Color := clBlack; Canvas.Font.Style := []; Canvas.Brush.Color := clWhite; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left, Rect.Top, AnsiLowerCase(Cells[ACol,ARow])); end end; end. |