Best delphi questions in April 2012

Delphi XE2 app doesn't respond on IPAD

10 votes


I try to use Delphi XE2 for develop for an iPad 3 professional application.
The configuration is ok.
I work on a MacBook Pro with Windows 7 on VMWare.
I create an HD app for iOS.
I put a timer, two labels and a button.
The timer refresh the time on label1 and the "on_click" event of the button change the label of label2.
It's compiled with Delphi.
I export to Xcode in the shared folder.
I launch Xcode and try with the iPad simulator.
All is ok.
I try to run on a real iPad, the application is launched but:
* the form is shown as a very small panel
* the timer seems not working but if i rotate the IPAD, the screen is refreshed and the time is shown.
* MY MAIN PROBLEM: if i tap on the button nothing happens.
I tried a lot of events, all works in delphi, in iPad simulator but not on the real iPad.

So, what the good options for fire events on a iPad ? Thanks in advance

EDIT:
I try to run the same application on a iPhone 4S and it works fine!
The trouble is only on iPad 3. I haven't no iPad 1 or 2 for testing.

I finally solved this trouble.
The installation of Delphi XE2 update 4 need to have XCODE 4.2 installed.
If you don't have it you can't install FireMonkey-iOS.dmg.
You must have too the latest version of XCODE 4.3.2 in parallels.
Of course, BE CAREFUL, of what version of Xcode is launched!
It easily to understand that for used the new IPAD (3) you must used at least Xcode 4.3.2.
If you use Xcode 4.2, your project will be compiled, running but now responding, because it don't know about iPad 3.
Enjoy.

How i can display the output of a rss feed in HTML format in a TWebBrowser?

8 votes

I Want to show the output of a rss feed in a formatted HTML in a TWebBrowser component, if a load this feed http://code.google.com/feeds/p/v8/svnchanges/basic in a TWebbrowser, this shows the content as a XML file

enter image description here

but if I use IE to load the same page

enter image description here

I tried injecting a css to the loaded IHTMLDocument2 as is suggested in this question CSS and TWebbrowser delphi but i still getting the same result.

The question is, how i can load the rss feed in TWebbrowser but showing the output as HTML document like IE does?

Just a guess, but you might try applying the following XSL stylesheet (taken from http://snippets.dzone.com/posts/show/1162 and modified as suggested by cherdt in the comments below):

<xsl:stylesheet version="1.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dc="http://purl.org/dc/elements/1.1/">
    <xsl:output method="html"/>
    <xsl:template match="/">
    <xsl:apply-templates select="/atom:feed/atom:head"/>
        <xsl:apply-templates select="/atom:feed"/>
    </xsl:template>
    <xsl:template match="atom:feed/atom:head">
        <h3><xsl:value-of select="atom:title"/></h3>
        <xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
        <xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
    </xsl:template>
    <xsl:template match="/atom:feed">
        <h3><xsl:value-of select="atom:title"/></h3>
        <xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
        <xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
        <ul>
            <xsl:apply-templates select="atom:entry"/>
        </ul>
    </xsl:template>
    <xsl:template match="atom:entry">
        <li>
            <a href="{atom:link[@rel='related']/@href}" title="{substring(atom:published, 0, 11)}"><xsl:value-of select="atom:title"/></a>
            <xsl:choose>
                <xsl:when test="atom:content != ''">
                    <p><xsl:value-of select="atom:content" disable-output-escaping="yes" /></p>
                </xsl:when>
                <xsl:otherwise>
                    <p><xsl:value-of select="atom:summary" disable-output-escaping="yes" /></p>
                </xsl:otherwise>
            </xsl:choose>
        </li>
    </xsl:template>
</xsl:stylesheet>

To the feed you are receiving. To transform the document, refer to this question's selected answer and then you could try to assign the resulting XML to the WebBrowser.

I am guessing that you are pointing your WebBrowser control to the feed, but using this approach you would need to download the feed using, for example, Indy (check out TIdHTTP and its Get() method), transform it, and then display in your control.

Please note that the above is just a guess, but I believe it is a good assumption. :)

Delphi: how to pass a list as a parameter to a SQL query?

8 votes

I have a list of integers or of strings and need to pass it as a parameter for a Delphi DataSet. How to do it?

Here is an example. MyQuery is something like:

select * from myTable where intKey in :listParam

I'd set a parameter as a list or array or something else:

MyQuery.ParamByName('listParam').AsSomething := [1,2,3];

and it would result in this query sent to the sql server:

select * from myTable where intKey in (1, 2, 3)

It would be even better if the solution would also work with strings, making this query:

select * from myTable where stringKey in :listParam

become:

select * from myTable where stringKey in ('a', 'b', 'c')

I believe this is a simple question, but "IN" isn't a good keyword for searching the web.

Please answer how I should configure the parameter in the IDE, the query and how to pass the parameters.

I'm using Delphi 7.

Edited: I'm considering the answer is "it isn't possible to do directly". If someone give me a non-hackish answer, the accepted answer will be changed.

AFAIK, it is not possible directly.

You'll have to convert the list into a SQL list in plain text.

For instance:

function ListToText(const Args: array of string): string; overload;
var i: integer;
begin
  result := '(';
  for i := 0 to high(Args) do 
    result := result+QuotedStr(Args[i])+',';
  result[length(result)] := ')';
end;


function ListToText(const Args: array of integer): string; overload;
var i: integer;
begin
  result := '(';
  for i := 0 to high(Args) do 
    result := result+IntToStr(Args[i])+',';
  result[length(result)] := ')';
end;

To be used as such:

SQL.Text := 'select * from myTable where intKey in '+ListToText([1,2,3]);
SQL.Text := 'select * from myTable where stringKey in '+ListToText(['a','b','c']);

IXMLDocument.SaveToFile() uses tab character for indentation instead of spaces

5 votes

I have an XML file, which is originally formatted using space indents (2 spaces for each nested item).

When I load and save this file using IXMLDocument, space indents are changing to the tab characters (code #9).

Here is the code:

 var
   FileName: String;
   Document: IXMLDocument;
 ...
 Document := XMLDoc.LoadXMLDocument(FileName);
 Document.SaveToFile(FileName);

I tried to use NodeIndentStr property - no result:

 Document := XMLDoc.LoadXMLDocument(FileName);
 Document.NodeIndentStr := '  ';
 Document.SaveToFile(FileName);

Used FormatXMLData too - no result:

 Document := XMLDoc.LoadXMLDocument(FileName);
 Document.XML.Text := XMLDoc.FormatXMLData(Document.XML.Text);
 Document.Active := True;
 Document.SaveToFile(FileName);

How can I save with space indents instead of tab characters?

There is an option in IXMLDocument where the parser can be told to preserve white spaces.

Use it like this :

Document.ParseOptions := 
  Document.ParseOptions+[poValidateOnParse]+[poPreserveWhiteSpace]; 

Disclaimer: I haven't tried it.