Dailycode.info

Short solution for short problems

implicit declaration of function is invalid in c99

As a c# developer, I'm sinning against a lot of syntax in objective C.

For one is the explicit calls to functions. I keep forgetting the square braces and hence getting the error:

implicit declaration of function is invalid in c99

Eg : FillValues(); should be [self FillValues];

- (void) FillValues

{

...

}


using sudzc.com and XCODE 4 (debugging and cleaning op the generated code) (UPDATE)

I started to debug the code generated by the sudzc.com generator. It generates a lot of classes to help you call a web service from objective C. The problem is that it is generating old code, and I do not appear to find an updated version of sudzc.com

So I started to debug the files. The first errors that could be removed where the function that are now automatically done by xcode because its now doing reference counting and cleaning up the objects for you. So get rid of all the autorelease, release, retain, … problems.

Then the next challenges. Code like this is also generating errors:

_node->_private = self;

The error it gives is: Implicit conversion of Objective-C pointer type ‘CXMLDocument’ to C pointer type ‘void’ requires a bridged cast. A solution found here: http://stackoverflow.com/questions/6868130/implicit-conversion-of-an-objective-c-pointer-to-void-is-disallowed-with-arc and looks like this:

_node->_private = (__bridge void*)self;

I’ll keep you updated on the rest of the problems and more, if I get the code running and a response from the .Net webservice.

I was a little too fast in declaring SUDZC couldn't manage xcode 4. Because there is a dropdown where you can choose: "Automatic Reference counting". To use this service on local web services, I decided to download the source, convert it to VS 2010 and host it locally. So far so good, today I will try to use SUDZC on this local WCF service, I'm curious to see if this will work?

When you use this Objective-C for iOS (Automatic Reference Counting) generation, its possible that the service calls will always return 0. The solution for this can be found here!


How to read an excel 2007 or 2010 file with the OleDbConnection.

How to read an excel 2007 or 2010 file with the OleDbConnection. My mistake was that I started out from a older connection string:

 

sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + uploadPath + ";Extended Properties=Excel 8.0;";

 

 

I got 2 different errors:

1 Could not find installable ISAM.

2 External table is not in the expected format.

It could only be fixed off course by using the correct connection string. So instead of using the Jet.OLEDB I used the ACE.OLEDB (Microsoft Access Database Engine 2010)

 

sConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + uploadPath + ";Extended Properties=Excel 12.0";

 

 

Then here is the fill code to read en Excel file into a DataSet

 

private void Upload(string uploadPath)
        {
            //Doupload
            string sConnectionString;
            //sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + uploadPath + ";Extended Properties=Excel 8.0;";
            sConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + uploadPath + ";Extended Properties=Excel 12.0";
           
            OleDbConnection Exlcon = newOleDbConnection(sConnectionString);
            string sDate = "";
            string sRowsNtInserted = "";
            int iRows = 0;
            DateTime date1;
            string sMonthName = "";
 
            try
            {
                Exlcon.Open();
            }
            catch
            {
                //ShowAlertMessage("Please select valid excel file.");
                return;
            }
            OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", Exlcon);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;
            DataSet objDataset1 = new DataSet();
            objAdapter1.Fill(objDataset1, "XLData");
 
            //Read the dataset line by line and process the tasks, see if they already exist.
            if (objDataset1 != null)
            {
                foreach (DataRow dr in objDataset1.Tables[0].Rows)
                {
                    //dosomething
                }
            }
        }

 

 

 


How to get a user controls parent form. (Windows forms)

I wanted to pass the owner form to all my ShowDialog calls. But lots of times I call this method from a user control. So I found a good solution on stackoverflow (it’s a recursive function that will loop over all parents and check if it’s a windows form): http://stackoverflow.com/questions/371464/get-components-parent-form

I changed it a little to fit my needs, also this project was VB.Net:

   

''' <summary>
    ''' Returns the parent System.Windows.form of the control
    ''' </summary>
    ''' <param name="parent"></param>
    ''' <returns>First parent form or null if no parent found</returns>
    ''' <remarks></remarks>
    Public Shared Function GetParentForm(ByVal parent As Control) As Form
        Dim form As Form = TryCast(parent, Form)
        If form IsNot Nothing Then
            Return form
        End If
        If parent IsNot Nothing Then
            ' Walk up the control hierarchy
            Return GetParentForm(parent.Parent)
        End If
        Return Nothing
        ' Control is not on a Form
    End Function

 

 

I just call this method new on all windows and user controls where I have a show dialog call:

 

frm.ShowDialog(GP_Global.GlobalFunctions.GetParentForm(Me))

 


FileDialog default settings.

 

I was using several ‘Open’ and ‘Save’ file dialogs on my screen, all for importing or exporting xml files. Instead if setting the default parameters for each dialog over again, I made this easy function that helps to set the default parameters:

    Private Shared Sub DialogInit(ByRef dialog As FileDialog)

        dialog.InitialDirectory = Environment.SpecialFolder.Desktop

        dialog.DefaultExt = "xml"

        dialog.Filter = "XML|*.xml"

    End Sub

 

Then all file dialogs call this method to set the default parameters and all dialogs act the same:

Using dialog As New OpenFileDialog

'dialog.InitialDirectory = Environment.SpecialFolder.Desktop 

           'dialog.DefaultExt = "xml"

           'dialog.Filter = "XML|*.xml"

           DialogInit(dialog)

           If dialog.ShowDialog() <> DialogResult.OK Then Return

           xmlFile = dialog.FileName

End Using

 

Another example:

Using dialog As New SaveFileDialog()

DialogInit(dialog)

           If dialog.ShowDialog() <> DialogResult.OK Then Return

           xmlFile = dialog.FileName

End Using