From 3b0f5be4bb76eca7fd0a4b3e67b78cbdf1768754 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 10 Aug 2008 15:34:47 +0000 Subject: [PATCH] Implement handling of maximum input length for the memo editor --- source/childwin.pas | 37 ++++++++++++++++++++++++++++--------- source/grideditlinks.pas | 3 ++- source/helpers.pas | 1 + 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/source/childwin.pas b/source/childwin.pas index 6142e3d6..bdd50c55 100644 --- a/source/childwin.pas +++ b/source/childwin.pas @@ -1164,6 +1164,7 @@ var col : TVirtualTreeColumn; rx : TRegExpr; ds : TDataSet; + ColType : String; begin Screen.Cursor := crHourglass; // Post pending UPDATE @@ -1287,25 +1288,39 @@ begin FSelectedTableColumns.First; while not FSelectedTableColumns.Eof do begin if FSelectedTableColumns.FieldByName('Field').AsWideString = ColName then begin + ColType := FSelectedTableColumns.FieldByName('Type').AsString; rx := TRegExpr.Create; rx.Expression := '^(tiny|small|medium|big)?int\b'; - if rx.Exec(FSelectedTableColumns.FieldByName('Type').AsWideString) then begin + if rx.Exec(ColType) then begin col.Alignment := taRightJustify; FDataGridResult.Columns[i].IsInt := True; end; rx.Expression := '^(float|double|decimal)\b'; - if rx.Exec(FSelectedTableColumns.FieldByName('Type').AsWideString) then begin + if rx.Exec(ColType) then begin col.Alignment := taRightJustify; FDataGridResult.Columns[i].IsFloat := True; end; rx.Expression := '^(date|datetime|time(stamp)?)\b'; - if rx.Exec(FSelectedTableColumns.FieldByName('Type').AsWideString) then + if rx.Exec(ColType) then FDataGridResult.Columns[i].IsDate := True; - rx.Expression := '^((tiny|medium|long)?text|varchar)\b'; - if rx.Exec(FSelectedTableColumns.FieldByName('Type').AsWideString) then + rx.Expression := '^((tiny|medium|long)?text|varchar)\b(\(\d+\))?'; + if rx.Exec(ColType) then begin FDataGridResult.Columns[i].IsText := True; + if ColType = 'tinytext' then + FDataGridResult.Columns[i].MaxLength := 255 + else if ColType = 'text' then + FDataGridResult.Columns[i].MaxLength := 65535 + else if ColType = 'mediumtext' then + FDataGridResult.Columns[i].MaxLength := 16777215 + else if ColType = 'longtext' then + FDataGridResult.Columns[i].MaxLength := 4294967295 + else if rx.Match[3] <> '' then + FDataGridResult.Columns[i].MaxLength := MakeInt(rx.Match[3]) + else // Fallback for unknown column types + FDataGridResult.Columns[i].MaxLength := MaxInt; + end; rx.Expression := '^((tiny|medium|long)?blob|(var)?binary)\b'; - if rx.Exec(FSelectedTableColumns.FieldByName('Type').AsWideString) then + if rx.Exec(ColType) then FDataGridResult.Columns[i].IsBlob := True; end; FSelectedTableColumns.Next; @@ -6067,10 +6082,14 @@ end; procedure TMDIChild.DataGridCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink); +var + MemoEditor: TMemoEditorLink; begin - if FDataGridResult.Columns[Column].IsText then - EditLink := TMemoEditorLink.Create - else + if FDataGridResult.Columns[Column].IsText then begin + MemoEditor := TMemoEditorLink.Create; + MemoEditor.MaxLength := FDataGridResult.Columns[Column].MaxLength; + EditLink := MemoEditor; + end else EditLink := TStringEditLink.Create; end; diff --git a/source/grideditlinks.pas b/source/grideditlinks.pas index 6bcf3751..e67fcaec 100644 --- a/source/grideditlinks.pas +++ b/source/grideditlinks.pas @@ -17,7 +17,7 @@ type FStopping: Boolean; // Set to True when the edit link requests stopping the edit action. public FieldType: Integer; - MaxInputLength: Integer; + MaxLength: Integer; constructor Create; destructor Destroy; override; function BeginEdit: Boolean; virtual; stdcall; @@ -68,6 +68,7 @@ begin FForm.Parent := Tree; FForm.memoText.Font := F; FForm.memoText.Text := Text; + FForm.memoText.MaxLength := MaxLength; end; diff --git a/source/helpers.pas b/source/helpers.pas index dd46971a..6b5ba199 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -49,6 +49,7 @@ type TGridColumn = record Name: WideString; DataType: Byte; // @see constants in mysql_structures.pas + MaxLength: Cardinal; IsPK: Boolean; IsBlob: Boolean; IsText: Boolean;