From eadeed1ae2b2e70cdf1561b7946f294e9333741c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Tue, 28 Apr 2009 22:35:00 +0000 Subject: [PATCH] Use helper methods where possible, and leave GUI stuff in form units. --- components/heidisql/include/const.inc | 2 ++ source/grideditlinks.pas | 7 +++++-- source/helpers.pas | 11 ----------- source/main.pas | 2 +- source/texteditor.pas | 5 ++++- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/components/heidisql/include/const.inc b/components/heidisql/include/const.inc index dd3d1c42..e56d3d73 100644 --- a/components/heidisql/include/const.inc +++ b/components/heidisql/include/const.inc @@ -290,6 +290,8 @@ const MSG_COPYMAXSIZE = 'Copying data is limited to %s but more data is available. ' + 'Only %s out of %s rows were copied.' + CRLF + CRLF + 'Increase the value in Tools > Preferences > Export if you need more.'; + SContainsNulCharFile = 'This file contains NUL characters. They have been converted to ASCII spaces (SP).'; + SContainsNulCharGrid = 'This cell contains NUL characters. They have been converted to ASCII spaces (SP). Press ESC to cancel editing.'; DBO_NAME = 'Name'; DBO_TYPE = 'Type'; diff --git a/source/grideditlinks.pas b/source/grideditlinks.pas index 99609100..24ec8ae3 100644 --- a/source/grideditlinks.pas +++ b/source/grideditlinks.pas @@ -6,7 +6,7 @@ interface uses Windows, Forms, Graphics, messages, VirtualTrees, texteditor, bineditor, ComCtrls, SysUtils, Classes, mysql_structures, Main, helpers, TntStdCtrls, WideStrings, StdCtrls, ExtCtrls, TntCheckLst, - Buttons, Controls, Types, PngSpeedButton; + Buttons, Controls, Types, PngSpeedButton, Dialogs; type TMemoEditorLink = class(TInterfacedObject, IVTEditLink) @@ -874,7 +874,10 @@ begin FColumn := Column; FTree.GetTextInfo(Node, Column, FEdit.Font, FTextBounds, NodeText); - CheckAndWarnIfNulChar(NodeText); + if ScanNulChar(NodeText) then begin + MessageDlg(SContainsNulCharGrid, mtInformation, [mbOK], 0); + NodeText := RemoveNulChars(NodeText); + end; FPanel.Parent := FTree; FEdit.Font.Color := clWindowText; FEdit.Text := NodeText; diff --git a/source/helpers.pas b/source/helpers.pas index 9dc276c6..735719de 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -189,7 +189,6 @@ type function CompareNumbers(List: TStringList; Index1, Index2: Integer): Integer; function ListIndexByRegExpr(List: TWideStrings; Expression: WideString): Integer; procedure RestoreSyneditStyles(Highlighter: TSynCustomHighlighter); - procedure CheckAndWarnIfNulChar(var Text: WideString); var MYSQL_KEYWORDS : TStringList; MainReg : TRegistry; @@ -2973,16 +2972,6 @@ begin end; -procedure CheckAndWarnIfNulChar(var Text: WideString); -begin - // Used by grid cell editors which use some TCustomEdit descendent which all cut a text at a NUL char - if Pos(#0, Text) > 0 then begin - MessageDlg('Text contains at least one NUL (\0) char. To avoid cutting off the rest they were just removed.', mtWarning, [mbOK], 0); - Text := WideStringReplace(Text, #0, '', [rfReplaceAll]); - end; -end; - - initialization diff --git a/source/main.pas b/source/main.pas index f3f64bd0..a70c7801 100644 --- a/source/main.pas +++ b/source/main.pas @@ -5479,7 +5479,7 @@ begin if ScanNulChar(filecontent) then begin filecontent := RemoveNulChars(filecontent); - MessageDlg('This file contains NUL characters. They have been converted to ASCII spaces (SP).', mtInformation, [mbOK], 0); + MessageDlg(SContainsNulCharFile, mtInformation, [mbOK], 0); end; SynMemoQuery.BeginUpdate; diff --git a/source/texteditor.pas b/source/texteditor.pas index 6efd7989..2618c68c 100644 --- a/source/texteditor.pas +++ b/source/texteditor.pas @@ -102,7 +102,10 @@ begin if LB <> '' then text := WideStringReplace(text, LB, CRLF, [rfReplaceAll]); - CheckAndWarnIfNulChar(text); + if ScanNulChar(text) then begin + MessageDlg(SContainsNulCharGrid, mtInformation, [mbOK], 0); + text := RemoveNulChars(text); + end; // TODO: Find out why the Delphi IDE insists hinting that this // property is ANSI when it is in fact a WideString.