S
Supermay
Unregistered / Unconfirmed
GUEST, unregistred user!
unit UTFieldListEditor;
interface
uses
SysUtils, Classes, Controls, ValEdit, ExtCtrls, StdCtrls, Graphics, Grids, Types;
type
TFieldListEditor = class(TStringGrid)
private
FTComboBox: TComboBox;
FOnDrawCell: TDrawCellEvent;
protected
procedure KeyPress(var Key: Char); override;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState); override;
public
constructor Create(AOwner: TComponent);
destructor Destroy;
end;
TFieldPanel = class(TCustomPanel)
private
FCaptionEditor: TEdit;
FCtl3D: Boolean;
FFieldListEditor: TFieldListEditor;
FFonts: TFont;
FTitleCaptions: TStrings;
function GetCaption: string;
function GetCaptionColor: TColor;
function GetColumnCount: Byte;
function GetRowColor: TColor;
function GetTitleColor: TColor;
function GetTitles: string;
procedure SetCaption(const Value: string);
procedure SetCaptionColor(Value: TColor);
procedure SetColumnCount(Value: Byte);
procedure SetCtl3D(Value: Boolean);
procedure SetFonts(Value: TFont);
procedure SetRowColor(Value: TColor);
procedure SetTitleColor(Value: TColor);
procedure SetTitles(const Value: string);
public
constructor Create(AOwner: TComponent);
destructor Destroy;
procedure RefreshTitle;
published
property Caption: string read GetCaption write SetCaption;
property CaptionColor: TColor read GetCaptionColor write SetCaptionColor;
property ColumnCount: Byte read GetColumnCount write SetColumnCount;
property Ctl3D: Boolean read FCtl3D write SetCtl3D;
property Fonts: TFont read FFonts write SetFonts;
property RowColor: TColor read GetRowColor write SetRowColor;
property TitleColor: TColor read GetTitleColor write SetTitleColor;
property Titles: string read GetTitles write SetTitles;
end;
implementation
{ TFieldPanel }
{
********************************* TFieldPanel **********************************
}
constructor TFieldPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCtl3D := True;
Self.Width := 350;
Self.Height := 330;
FFonts := TFont.Create;
FTitleCaptions := TStringList.Create;
FTitleCaptions.CommaText := '第一列 第二列 第三列 第四列';
FCaptionEditor := TEdit.Create(AOwner);
FCaptionEditor.Parent := Self;
FCaptionEditor.Align := alTop;
FCaptionEditor.Text := 'TableCaption';
FFieldListEditor := TFieldListEditor.Create(AOwner);
FFieldListEditor.Parent := Self;
FFieldListEditor.Align := alClient;
FFieldListEditor.ColCount := 4;
FFieldListEditor.DefaultRowHeight := 18;
RefreshTitle;
end;
destructor TFieldPanel.Destroy;
begin
FFonts.Free;
FTitleCaptions.Free;
FCaptionEditor.Free;
FFieldListEditor.Free;
inherited Destroy;
end;
function TFieldPanel.GetCaption: string;
begin
Result := FCaptionEditor.Text;
end;
function TFieldPanel.GetCaptionColor: TColor;
begin
Result := FCaptionEditor.Color;
end;
function TFieldPanel.GetColumnCount: Byte;
begin
Result := FFieldListEditor.ColCount;
end;
function TFieldPanel.GetRowColor: TColor;
begin
Result := FFieldListEditor.Color;
end;
function TFieldPanel.GetTitleColor: TColor;
begin
Result := FFieldListEditor.FixedColor;
end;
function TFieldPanel.GetTitles: string;
begin
Result := FTitleCaptions.DelimitedText;
end;
procedure TFieldPanel.RefreshTitle;
var
i, MaxColumn, MinColumn: Integer;
begin
MaxColumn := FTitleCaptions.Count;
FFieldListEditor.ColCount := MaxColumn;
FFieldListEditor.Rows[0].Clear;
for i := 0 to MaxColumn - 1 do
begin
FFieldListEditor.Cells[i, 0] := FTitleCaptions.Strings;
end;
end;
procedure TFieldPanel.SetCaption(const Value: string);
begin
FCaptionEditor.Text := Value;
end;
procedure TFieldPanel.SetCaptionColor(Value: TColor);
begin
FCaptionEditor.Color := Value;
end;
procedure TFieldPanel.SetColumnCount(Value: Byte);
begin
if FFieldListEditor.ColCount <> Value then
begin
FFieldListEditor.ColCount := Value;
end;
end;
procedure TFieldPanel.SetCtl3D(Value: Boolean);
begin
if FCtl3D <> Value then
begin
FCtl3D := Value;
FFieldListEditor.Ctl3D := Value;
FCaptionEditor.Ctl3D := Value;
Perform(CM_CTL3DCHANGED, 0, 0);
end;
end;
procedure TFieldPanel.SetFonts(Value: TFont);
begin
FFonts := Value;
FFieldListEditor.Font := Value;
FCaptionEditor.Font := Value;
end;
procedure TFieldPanel.SetRowColor(Value: TColor);
begin
FFieldListEditor.Color := Value;
end;
procedure TFieldPanel.SetTitleColor(Value: TColor);
begin
FFieldListEditor.FixedColor := Value;
end;
procedure TFieldPanel.SetTitles(const Value: string);
begin
FTitleCaptions.DelimitedText := Value;
RefreshTitle;
end;
{ TFieldListEditor }
{
******************************* TFieldListEditor *******************************
}
constructor TFieldListEditor.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FixedCols := 0;
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goTabs];
FTComboBox := TComboBox.Create(AOwner);
end;
destructor TFieldListEditor.Destroy;
begin
FTComboBox.Free;
end;
procedure TFieldListEditor.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
if ACol=2 And ARow>0 then
begin
FTComboBox.Top := Top + DefaultRowHeight * ARow + 5;
FTComboBox.Left := Left+2;
FTComboBox.Width := DefaultColWidth - 1;
FTComboBox.Parent := Self;
Self.InsertControl(FTComboBox);
FTComboBox.Items.Add('eeeee');
FTComboBox.Items.Add('uuuuu');
FTComboBox.Items.Add('ppppp');
FTComboBox.Items.Add('ccccc');
end;
end;
procedure TFieldListEditor.KeyPress(var Key: Char);
begin
if Key = #13 then
begin
if Col < ColCount - 1 then
Col := Col + 1
else
begin
if Row < RowCount - 1 then
begin
Row := Row + 1;
Col := 0;
end
else
begin
RowCount := RowCount + 1;
Row := RowCount - 1;
Col := 0;
end;
end;
end;
inherited KeyPress(Key);
end;
end.
interface
uses
SysUtils, Classes, Controls, ValEdit, ExtCtrls, StdCtrls, Graphics, Grids, Types;
type
TFieldListEditor = class(TStringGrid)
private
FTComboBox: TComboBox;
FOnDrawCell: TDrawCellEvent;
protected
procedure KeyPress(var Key: Char); override;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState); override;
public
constructor Create(AOwner: TComponent);
destructor Destroy;
end;
TFieldPanel = class(TCustomPanel)
private
FCaptionEditor: TEdit;
FCtl3D: Boolean;
FFieldListEditor: TFieldListEditor;
FFonts: TFont;
FTitleCaptions: TStrings;
function GetCaption: string;
function GetCaptionColor: TColor;
function GetColumnCount: Byte;
function GetRowColor: TColor;
function GetTitleColor: TColor;
function GetTitles: string;
procedure SetCaption(const Value: string);
procedure SetCaptionColor(Value: TColor);
procedure SetColumnCount(Value: Byte);
procedure SetCtl3D(Value: Boolean);
procedure SetFonts(Value: TFont);
procedure SetRowColor(Value: TColor);
procedure SetTitleColor(Value: TColor);
procedure SetTitles(const Value: string);
public
constructor Create(AOwner: TComponent);
destructor Destroy;
procedure RefreshTitle;
published
property Caption: string read GetCaption write SetCaption;
property CaptionColor: TColor read GetCaptionColor write SetCaptionColor;
property ColumnCount: Byte read GetColumnCount write SetColumnCount;
property Ctl3D: Boolean read FCtl3D write SetCtl3D;
property Fonts: TFont read FFonts write SetFonts;
property RowColor: TColor read GetRowColor write SetRowColor;
property TitleColor: TColor read GetTitleColor write SetTitleColor;
property Titles: string read GetTitles write SetTitles;
end;
implementation
{ TFieldPanel }
{
********************************* TFieldPanel **********************************
}
constructor TFieldPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCtl3D := True;
Self.Width := 350;
Self.Height := 330;
FFonts := TFont.Create;
FTitleCaptions := TStringList.Create;
FTitleCaptions.CommaText := '第一列 第二列 第三列 第四列';
FCaptionEditor := TEdit.Create(AOwner);
FCaptionEditor.Parent := Self;
FCaptionEditor.Align := alTop;
FCaptionEditor.Text := 'TableCaption';
FFieldListEditor := TFieldListEditor.Create(AOwner);
FFieldListEditor.Parent := Self;
FFieldListEditor.Align := alClient;
FFieldListEditor.ColCount := 4;
FFieldListEditor.DefaultRowHeight := 18;
RefreshTitle;
end;
destructor TFieldPanel.Destroy;
begin
FFonts.Free;
FTitleCaptions.Free;
FCaptionEditor.Free;
FFieldListEditor.Free;
inherited Destroy;
end;
function TFieldPanel.GetCaption: string;
begin
Result := FCaptionEditor.Text;
end;
function TFieldPanel.GetCaptionColor: TColor;
begin
Result := FCaptionEditor.Color;
end;
function TFieldPanel.GetColumnCount: Byte;
begin
Result := FFieldListEditor.ColCount;
end;
function TFieldPanel.GetRowColor: TColor;
begin
Result := FFieldListEditor.Color;
end;
function TFieldPanel.GetTitleColor: TColor;
begin
Result := FFieldListEditor.FixedColor;
end;
function TFieldPanel.GetTitles: string;
begin
Result := FTitleCaptions.DelimitedText;
end;
procedure TFieldPanel.RefreshTitle;
var
i, MaxColumn, MinColumn: Integer;
begin
MaxColumn := FTitleCaptions.Count;
FFieldListEditor.ColCount := MaxColumn;
FFieldListEditor.Rows[0].Clear;
for i := 0 to MaxColumn - 1 do
begin
FFieldListEditor.Cells[i, 0] := FTitleCaptions.Strings;
end;
end;
procedure TFieldPanel.SetCaption(const Value: string);
begin
FCaptionEditor.Text := Value;
end;
procedure TFieldPanel.SetCaptionColor(Value: TColor);
begin
FCaptionEditor.Color := Value;
end;
procedure TFieldPanel.SetColumnCount(Value: Byte);
begin
if FFieldListEditor.ColCount <> Value then
begin
FFieldListEditor.ColCount := Value;
end;
end;
procedure TFieldPanel.SetCtl3D(Value: Boolean);
begin
if FCtl3D <> Value then
begin
FCtl3D := Value;
FFieldListEditor.Ctl3D := Value;
FCaptionEditor.Ctl3D := Value;
Perform(CM_CTL3DCHANGED, 0, 0);
end;
end;
procedure TFieldPanel.SetFonts(Value: TFont);
begin
FFonts := Value;
FFieldListEditor.Font := Value;
FCaptionEditor.Font := Value;
end;
procedure TFieldPanel.SetRowColor(Value: TColor);
begin
FFieldListEditor.Color := Value;
end;
procedure TFieldPanel.SetTitleColor(Value: TColor);
begin
FFieldListEditor.FixedColor := Value;
end;
procedure TFieldPanel.SetTitles(const Value: string);
begin
FTitleCaptions.DelimitedText := Value;
RefreshTitle;
end;
{ TFieldListEditor }
{
******************************* TFieldListEditor *******************************
}
constructor TFieldListEditor.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FixedCols := 0;
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goTabs];
FTComboBox := TComboBox.Create(AOwner);
end;
destructor TFieldListEditor.Destroy;
begin
FTComboBox.Free;
end;
procedure TFieldListEditor.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
if ACol=2 And ARow>0 then
begin
FTComboBox.Top := Top + DefaultRowHeight * ARow + 5;
FTComboBox.Left := Left+2;
FTComboBox.Width := DefaultColWidth - 1;
FTComboBox.Parent := Self;
Self.InsertControl(FTComboBox);
FTComboBox.Items.Add('eeeee');
FTComboBox.Items.Add('uuuuu');
FTComboBox.Items.Add('ppppp');
FTComboBox.Items.Add('ccccc');
end;
end;
procedure TFieldListEditor.KeyPress(var Key: Char);
begin
if Key = #13 then
begin
if Col < ColCount - 1 then
Col := Col + 1
else
begin
if Row < RowCount - 1 then
begin
Row := Row + 1;
Col := 0;
end
else
begin
RowCount := RowCount + 1;
Row := RowCount - 1;
Col := 0;
end;
end;
end;
inherited KeyPress(Key);
end;
end.