adem0x / txquery

Automatically exported from code.google.com/p/txquery
Other
0 stars 0 forks source link

Fix for: SQL Text Truncated in RichEdit using SinxtaxHighLighter component (Unicode eversion 2.08) #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
This will only have probnlems when working with Unicode versions of delphi 
(D2009 and newer)

1. Open the Demo app of TxQuery or create a new project add a txquery, 
TSyntaxHighlighter and a TRichEdit and Bind them
2. if using the demo app, select any of the staments (JOIN, ect) or Add A large 
SQL statement like:
'SELECT * FROM Customer c, Orders o, Items i, 
Parts p WHERE (c.CustNo = o.CustNo) And 
(o.OrderNo = i.OrderNo) And (i.PartNo = p.PartNo) 
And c.CustNo > 1300 AND c.CustNo < 2000;  '

3. The statement will look truncated

What is the expected output? What do you see instead?

The statement should look the same as the input sql, only colored, but instead 
it looks truncated.

What version of the product are you using? On what operating system?
latest TXQuery 2.08 SVN, windows 7, Delphi XE Architect

The solutions is in two steps:

1) In Internal procedure strToRichEdit of TSyntaxHighlighter.Execute method
-------------------------------
Procedure strToRichEdit( Const S: String );
  Var
    //aMem: TMemoryStream;  {commented by fduenas}
    aMem: TStringStream;  {changed by fduenas}
    SelStart: Integer;
  Begin
    //aMem := TMemoryStream.Create; {commented by fduenas}
    aMem := TStringStream.Create( s ); {patched by fduenas} //Using a TStringStream avoids casting the var 'S' to AnsiString 
    FChanging := True;
    SelStart := 0; //Basri
    Try
      //aMem.Write( Pointer( S )^, Length( S ) ); 
      //aMem.Write( Pointer( AnsiString(S) )^, Length( AnsiString(S) )  ); {commented by fduenas}
      aMem.Position := 0;
      If FEditor.Focused Then
        SelStart := FEditor.SelStart;
      //LockWindowUpdate( FEditor.Handle );
      fEditor.OnChange := nil;
       FEditor.OnSelectionChange := nil;
      FEditor.Lines.BeginUpdate;
      FEditor.Lines.LoadFromStream( aMem );
      FEditor.Lines.EndUpdate;
      feditor.OnChange := MyOnChange;
      FEditor.OnSelectionChange := MyOnSelectionChange;
      If FEditor.Focused Then
        FEditor.SelStart := SelStart;
      //LockWindowUpdate( 0 );
    Finally
      aMem.Free;
      FChanging := False;
    End;
  End;
------------------------------------------------------------------
2) at Execute's body change the line:
inputStream.WriteBuffer( Pointer( S )^, Length( S ) ); 

To
  inputStream.WriteBuffer( Pointer( S )^, Length( S )*SizeOf(Char) );

This will look like:
------------------------------------------------------------------
Begin
  Reslt := '';
  RtfHeader := '';
{$IFDEF XQDEMO}
  If Not IsDelphiRunning Then
  Begin
    ShowAbout;
    Raise Exception.Create( SDelphiIsNotRunning );
  End;
{$ENDIF}

  If Not Assigned( FEditor ) Or ( csDestroying In ComponentState ) Then
    Exit;
  s := FEditor.Text + ' ';
  inputStream := TMemoryStream.Create;
  //inputStream.WriteBuffer( Pointer( S )^, Length( S ) ); {commented by fduenas}
  inputStream.WriteBuffer( Pointer( S )^, Length( S )*SizeOf(Char) ); {patched by fduenas}
  inputStream.Seek( 0, 0 );
  outputStream := TMemoryStream.create;
---------------------------------------------------------------------

I'm attaching patched SyntaxHi.pas for a full replacement

regards

Original issue reported on code.google.com by fdue...@gmail.com on 6 Jun 2011 at 2:42

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Sorry  Im' using latest 2.17 version, not 2.08, I wrote incorrect version 
number in the title.

Original comment by fdue...@gmail.com on 6 Jun 2011 at 2:47