Archives

Archives / 2004 / March
  • Oracle 10g for Windows

    Jan-Erik reports on his blog:

    Yes! At last it is here and I just got it up and running on my XP machine.

    For some strange reason I haven't been able to install it on my newer and faster Win2K machine. It keeps on saying

      Error in starting the service. The service 
      OracleCSService was not found
    

    I have tried deinstalling all my old Oracle stuff but it still wont work... darn!

  • How to move the cursor to the correct line in a RichTextBox

    I'm sure there is a really simple way of doing this, but this works out for me. Please write a comment and tell me how it's supposed to be done if this isn't the best way (which I'm sure it isn't ;)

    public void SetCaretLine(int linenr)

    {

          if(linenr > this.richTextBox1.Lines.Length)

          {

                MessageBox.Show("Line " + linenr + " is out of range.");

                return;

          }

     

          int row = 1;

          int charCount = 0;

          foreach(string line in richTextBox1.Lines)

          {

                charCount+=line.Length + 1;

                row++;

                if(row == linenr)

                {

                      //set the caret here

                      this.richTextBox1.SelectionStart = charCount;

                      break;

                }

          }

    }

    Well? I guess there's a win32 api lurking in the shadows that does this in 1 or 2 lines of code - then show me already!

  • Use LockWindowUpdate to get flicker-free RichTextBox update

    Very simple, but I had to dig around to find it so I might as well share it here. I do lots of updates to a RichTextBox while colorparsing some code, and I didn't like the flickering.

    Since there is no BeginUpdate() or similar, I had to use Win32 api from user32.dll:

          [DllImport("user32.dll")]

          public static extern bool LockWindowUpdate(IntPtr hWndLock);

    To use it just:

    try

    {

          LockWindowUpdate(richTextBox1.Handle);

          //change colors and stuff in the RichTextBox

    }

    finally

    {

          LockWindowUpdate(IntPtr.Zero);

    }

     

    UPDATE: I got a tip fom Kevin Westhead to use SendMessage() with WM_SETREDRAW instead:

     

    I think it's better to use SendMessage with WM_SETREDRAW to enable/disable drawing on a window since LockWindowUpdate can only be applied to one window. This means that you might not be able to lock your window if someone else has already locked a window, or someone else could unlock your window without you knowing.

    So if you prefer this alternative, please do like this:

     

    private const int WM_SETREDRAW      = 0x000B;

    private const int WM_USER           = 0x400;

    private const int EM_GETEVENTMASK   = (WM_USER + 59);

    private const int EM_SETEVENTMASK   = (WM_USER + 69);

     

    [DllImport("user32", CharSet = CharSet.Auto)]

    private extern static IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);

     

    IntPtr eventMask = IntPtr.Zero;

    try

    {

          // Stop redrawing:

          SendMessage(richTextBox1.Handle, WM_SETREDRAW, 0, IntPtr.Zero);

          // Stop sending of events:

          eventMask = SendMessage(richTextBox1.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);

     

          // change colors and stuff in the RichTextBox

    }

    finally

    {

          // turn on events

          SendMessage(richTextBox1.Handle, EM_SETEVENTMASK, 0, eventMask);

          // turn on redrawing

          SendMessage(richTextBox1.Handle, WM_SETREDRAW, 1, IntPtr.Zero);

    }

     

    Thanks Kevin!

  • Better Visio stencils for UML drawing

    Pavel Hruby keeps a set of Visio stencils for UML that are intuitive and easy to use. Very good if you want to do a bit of free hand UML drawing. From his webby:

    Thank you for your interest in the stencil and template for the drawing tool Visio. The stencil supports all symbols of UML 1.5, specified in the OMG document formal/03-03-01, as well as previous UML versions 1.4, 1.3 and 1.1. The stencil also contains several symbols of the newly adopted UML 2.0, particularly, the Socket and new Pseudostate symbols, and additional symbols not specified by the standard, but used by many UML users. 

    I can recommend them for sure. The stencils are free to be used, copied and modified as you like, and can be downloaded here. Pavel, my humble thanks to you for giving such nice stuff away.

     

     

  • Found a bug in SqlHelper's UpdateDataset() method

    UPDATE: This is for version 2.0. I just did a few searches on the GotDotNet workspace and saw than another fellow had reported the same thing in their forum. But there were no replies.

    UPDATE 2: I couldn't get into their Bug Tracker coz of some Passport error before. But I can now see that the problem with the UpdateDataset() method is on the list. I guess it will be fixed in version 3.

    After a couple of hours of debugging I finally found the bug. It wasn't in my code, it was in the UpdateDataset() method of SqlHelper!

    I had a strongly typed DataSet with 2 tables in it (with a relation between them) that I wanted to add to the database. It was an order (in one table) with several order details (in another table). Problem was the order details were never written to the database!

    So, first I called on SqlHelper.UpdateDataset() for the order data, then I did the same with the order details, but the problem was that the UpdateDataset() method calls dataSet.AcceptChanges() after the dataAdapter.Update(), and this changes EVERY datarow and datatable in the whole dataset! The result of that was that my order details were never written to the database, because they were flagged in the RowState as "unchanged". The correct thing (I guess) would be to accept changes on the affected table only as the code at the bottom of this post shows.

    This is the original code with the error in it:

        Public Overloads Shared Sub UpdateDataset(ByVal insertCommand As SqlCommand, ByVal deleteCommand As SqlCommand, ByVal updateCommand As SqlCommand, ByVal dataSet As DataSet, ByVal tableName As String)

     

            If (insertCommand Is Nothing) Then Throw New ArgumentNullException("insertCommand")

            If (deleteCommand Is Nothing) Then Throw New ArgumentNullException("deleteCommand")

            If (updateCommand Is Nothing) Then Throw New ArgumentNullException("updateCommand")

            If (dataSet Is Nothing) Then Throw New ArgumentNullException("dataSet")

            If (tableName Is Nothing OrElse tableName.Length = 0) Then Throw New ArgumentNullException("tableName")

     

            ' Create a SqlDataAdapter, and dispose of it after we are done

            Dim dataAdapter As New SqlDataAdapter

            Try

                ' Set the data adapter commands

                dataAdapter.UpdateCommand = updateCommand

                dataAdapter.InsertCommand = insertCommand

                dataAdapter.DeleteCommand = deleteCommand

     

                ' Update the dataset changes in the data source

                dataAdapter.Update(dataSet, tableName)

     

                ' Commit all the changes made to the DataSet

                ' This is a buggy one, it resets other tables RowState to "unchanged" /Johan

                dataSet.AcceptChanges()

            Finally

                If (Not dataAdapter Is Nothing) Then dataAdapter.Dispose()

            End Try

        End Sub

    And this is how it should look:

        Public Overloads Shared Sub UpdateDataset(ByVal insertCommand As SqlCommand, ByVal deleteCommand As SqlCommand, ByVal updateCommand As SqlCommand, ByVal dataSet As DataSet, ByVal tableName As String)

     

            If (insertCommand Is Nothing) Then Throw New ArgumentNullException("insertCommand")

            If (deleteCommand Is Nothing) Then Throw New ArgumentNullException("deleteCommand")

            If (updateCommand Is Nothing) Then Throw New ArgumentNullException("updateCommand")

            If (dataSet Is Nothing) Then Throw New ArgumentNullException("dataSet")

            If (tableName Is Nothing OrElse tableName.Length = 0) Then Throw New ArgumentNullException("tableName")

     

            ' Create a SqlDataAdapter, and dispose of it after we are done

            Dim dataAdapter As New SqlDataAdapter

            Try

                ' Set the data adapter commands

                dataAdapter.UpdateCommand = updateCommand

                dataAdapter.InsertCommand = insertCommand

                dataAdapter.DeleteCommand = deleteCommand

     

                ' Update the dataset changes in the data source

                dataAdapter.Update(dataSet, tableName)

     

                ' Commit all the changes made to the DataSet

                ' Commit changes to THIS TABLE ONLY! /Johan

                dataSet.Tables(tableName).AcceptChanges()

            Finally

                If (Not dataAdapter Is Nothing) Then dataAdapter.Dispose()

            End Try

        End Sub

    It's late, maybe I'm wrong, but things work way better now. Am I wrong? I'll try to notify the devs about this.

  • Getting Intel 815 display adapter to work in Longhorn

    I installed Longhorn on a separate box a couple of days ago but it couldn't find a suitable driver for the built in Intel 815 graphics chip. I tried to download and run the driver installer from Intel, but the program bombed. Then I extracted all the files from the install program (with WinRar), and pointed the the display driver installation wizard at the win2000 folder from the extracted files. Yay! I now got a high rez Longhorn!