LCL, implements MaxLength in grid's TCompositeCellEditor, fix issue #20951

git-svn-id: trunk@34567 -
This commit is contained in:
jesus 2012-01-03 20:41:42 +00:00
parent 554486927a
commit 6f5bccc376
2 changed files with 30 additions and 3 deletions

View File

@ -2399,8 +2399,13 @@ begin
if (FDatalink<>nil) and FDatalink.Active then begin
inherited SelectEditor;
if (Editor is TCustomEdit) and (SelectedField is TStringField) then
TCustomEdit(Editor).MaxLength := SelectedField.Size;
if (SelectedField is TStringField) then begin
if (Editor is TCustomEdit) then
TCustomEdit(Editor).MaxLength := SelectedField.Size
else
if (Editor is TCompositeCellEditor) then
TCompositeCellEditor(Editor).MaxLength := SelectedField.Size;
end;
if Assigned(OnSelectEditor) then begin
aEditor:=Editor;

View File

@ -276,6 +276,8 @@ type
FEditors: array of TEditorItem;
procedure DispatchMsg(msg: TGridMessage);
function GetActiveControl: TWinControl;
function GetMaxLength: Integer;
procedure SetMaxLength(AValue: Integer);
protected
function DoUTF8KeyPress(var UTF8Key: TUTF8Char): boolean; override;
procedure msg_GetValue(var Msg: TGridMessage); message GM_GETVALUE;
@ -294,6 +296,7 @@ type
destructor Destroy; override;
procedure AddEditor(aEditor: TWinControl; aAlign: TAlign; ActiveCtrl:boolean);
procedure SetFocus; override;
property MaxLength: Integer read GetMaxLength write SetMaxLength;
end;
@ -11520,6 +11523,25 @@ begin
Feditors[i].Editor.Dispatch(msg);
end;
function TCompositeCellEditor.GetMaxLength: Integer;
var
AEditor: TWinControl;
begin
result := 0;
AEditor := GetActiveControl;
if AEditor is TCustomEdit then
result := TCustomEdit(AEditor).MaxLength;
end;
procedure TCompositeCellEditor.SetMaxLength(AValue: Integer);
var
AEditor: TWinControl;
begin
AEditor := GetActiveControl;
if AEditor is TCustomEdit then
TCustomEdit(AEditor).MaxLength := AValue;
end;
function TCompositeCellEditor.GetActiveControl: TWinControl;
var
i: Integer;
@ -11703,7 +11725,7 @@ begin
end;
end;
destructor TCompositeCellEditor.destroy;
destructor TCompositeCellEditor.Destroy;
begin
SetLength(FEditors, 0);
inherited destroy;