Tuesday, September 25, 2007

Blog searching

Blogger offers the posibility to search a specific blog with a query, which will return all the blogposts that meets the criteria.

For instance http://beensoft.blogspot.com/search?q=TWebbrowser will return all my blogposts about TWebbrowser including the Fooling around with series. Did not know that, thought I let you know!

Thursday, September 20, 2007

On with RAD Studio 2007 with mixed feelings

Yesterday I installed the RAD Studio 2007, over my existing Delphi 2007 for Win32 (Update 3) installation.
Installation gave no problem, except for a few packages that needed to be recompiled. Although I don't need RAD Studio 2007 anymore (since it does not have a winform designer), I was curious about the new ECO IV for VCL.NET.
Well it looks that ECO is only available in the Architect edition, which it was in the BDS2005 erra, as I recall. In BDS2006 it was introduced in all the SKU's at different levels.

Anyway I have mixed feelings for this release, at one hand it fast, stable (iow it rocks!), but on the other hand it misses important features compared to BDS2006.

Go Delphi for Win32!

Friday, September 14, 2007

Fooling around with TWebbrowser #3

Some more tips to make a webbrowser application that rocks!

Get the right popupwindow size
In episode #2 we managed to retain the ASP.NET Session for popup windows in our TWebbrowser application.
Initially we don't know what the size of our popup form must be. Fortunately TWebbrowser has two events for that, so that we can size our window accordingly.
Use the OnWindowSetHeight and OnWindowSetWidth event to do this.

procedure TfrmPopUpBrowser.WebBrowser1WindowSetHeight(
ASender: TObject; Height: Integer);
begin
Self.Height := WebBrowser1.Height + 20;
end;

procedure TfrmPopUpBrowser.WebBrowser1WindowSetWidth(
ASender: TObject; Width: Integer);
begin
Self.Width := WebBrowser1.Width + 20;
end;

The additional distance of 20, is to avoid scrollbars.

Filling up a combobox with the visited websites
If you use a combobox to harvest the visited websites, just like Internet Explorer then you could use the OnDocumentComplete event to get the complete URL and then add it to your combobox. I use this event for three reasons:

1. It gives you a complete URL (not www.codegear.com not http://www.codegear.com but http://www.codegear.com/)
2. If the typed address is not available (a non existing website) the OnNavigateError event will trigger, so you could then decide not to add the URL to the webbrowser.
3. Having a good URL gives the ability to locate the URL in combobox again if the user navigates back to the page.

You don't have this advantages if you add the URL into the combobox directly after input.

procedure TfrmPopUpBrowser.WebBrowser1DocumentComplete(
ASender: TObject;
const pDisp: IDispatch;
var URL: OleVariant);
begin
AddAddressToCombobox(URL);
end;

procedure TfrmPopUpBrowser.AddAddressToCombobox(
Adres : string);
begin
Adres := LowerCase(Adres);
If (Adres <> '')
and (cboAddress.Items.IndexOf(Adres) = -1) then begin
cboApplication.Items.Add(Adres);
end;
end;
end;

Enable/Disable navigatebuttons (back/forward) automatically
If you put two buttons on your form to navigate back and forward in the webbrowser you will get an error if there is no page to go back to. (Webbrowser1.GoBack and Webbrowser1.GoForward methods)
You can use the OnCommandChange event to make this buttons 'case sensitive':

procedure TfrmPopUpBrowser.WebBrowser1CommandStateChange(
ASender: TObject; Command: Integer; Enable: WordBool);
begin
case Command of
CSC_NAVIGATEBACK: tbApplicationBack.Enabled := Enable;
CSC_NAVIGATEFORWARD: tbApplicationNext.Enabled := Enable;
end;
end;

Add a progress bar to your application
If you want to see the load progress of a page then use the OnProgressChange event.

procedure TfrmPopUpBrowser.WebBrowser1ProgressChange(
ASender: TObject; Progress, ProgressMax: Integer);
begin
ProgressBar.Max := ProgressMax;
ProgressBar.Min := 0;
ProgressBar.Position := Progress;
end;

Have the url in your statusbar or label
Use the OnStatusChange event to show the navigated address in a label or statusbar.

procedure TfrmPopUpBrowser.WebBrowser1StatusTextChange(
ASender: TObject; const Text: WideString);
begin
StatusBar.SimpleText := Text;
end;

Thursday, September 13, 2007

SA or not SA

Is SA worth while?
This is what Bruce McGee asks himself (and us) in this blogpost.
From a financial point of view it is a good deal. Personally I am very disappointed with my first SA experience.

Together with the Delphi 2007 for Win32 edition I bought software assurance because I tend to use the Delphi .NET personality for my winforms development (What was I thinking?). At that time nothing indicated that the winforms designer was not in the RAD Studio later that year.
Now that RAD Studio is out, it is kind of funny (ahum sad) that there is no reason, for me, to even install it. The Update 3 is all I need.

Is SA worth while?

Wednesday, September 12, 2007

Fooling around with TWebbrowser #2

In the last episode of this serie (9 january 2006) we talked about the fact that we could use the TWebbrowser component to display simple webpages within our Delphi application.
Recently this project extended and was used to hold a complex ASP.NET webapplication, which gave some additional problems with the ASP.NET Session object. The problem is that this webapplication popups several windows (Internet Explorer windows) which looses the session of the webapplication.
As a result the user must login on every browser, which is a showstopper of course.

The cause of this is that the webserver sees our application as a different process compared to Internet Explorer. (ASP.NET sessions are process dependent) Different process, different session. The solution of this was rather simple, although a little hard to find.

How to retain the browser session within your application
The trick is to get the popup to run into the same process as our application, so basically to run it in our application.
TWebbrowser has a NewWindow2 event for this. In this event you can specify the application to be used throught the ppDisp (IDispatch) parameter. (our application, in this event)

Suppose you have a second form, Form2, containing another TWebbrowser, you could 'redirect' the new window like this:

procedure TForm1.WebBrowser1NewWindow2(ASender: TObject;
var ppDisp: IDispatch; var Cancel: WordBool);
begin
ppDisp := Form2.WebBrowser1.Application;
Form2.Show;
end;



Quite simple, isn't it?
To let our form act in the window-name resolution it is wise to set the RegisterAsBrowser property to true.

More information can be found on knAlertz:
How to maintain the ASP.NET session state
How to use the WebBrowser control NewWindow2 event in Visual Basic .NET

Monday, September 10, 2007

VB developers, now is the time to shift to Delphi

Every now and then the discussion on how do we get 'the abandoned VB6 developer' into Delphi community pops up.

If you are VB developer, who wants to get into Delphi, now is the time to move to Delphi! If you do, and you should, you might find one of the following links usefull:

Delphi versus VB
- Delphi for Visual Basic developers by Delphi About
- VB to Delphi at Cyber Matrix.
- Migrating from VB to Delphi Whitepaper (PDF) by CodeGear.

Delphi the IDE, and the language
- Marco Cantu's essential Pascal all about the basics of Object Pascal, the language used in Delphi.
- Marco Cantu's all about Delphi Essential Delphi the IDE combined with the language.
- Zarko Gajic's delphi.about.com, with lot's of tutorials and sources.
- Delphiland offers online lessons for beginners and intermediate users
- Delphi basics provides help and reference for the fundamentals of the Delphi language.

Delphi the community
- CodeGear Delphi product page
- CodeGear Developer Network Delphi
- Delphi Newswhat Newsgroups and Blog aggregator
- Also via newsgroups.codegear.com.
Tip! Don't miss the Delphi non-technical newsgroup!

Books on Lulu
All Delphi books on Lulu
Marco Cantu's Delphi books on Lulu
Bob Swart's books on Lulu

Delphi wikis
Delphi Video's
Delphi Useful sites

Delphi blogs
Delphifeeds blog aggregator

More resources?

Wednesday, September 05, 2007

CodeGear RAD Studio 2007 announced

CodeGear announced in this press release the upcoming new version of BDS 2006 / Delphi 2007 for Win32, now called CodeGear RAD Studio 2007, to be available this month.

More information can be found on the RAD Studio product page.

Update! Technical datasheet is available here.
Much more links (product pdf's etcetera) can be found on David I's blog here.

Use an image as your UIBarButtonItem

Using an image as your UIBarButtonItem in your navigationcontroller bar can only be achieved by using a common UIButton as the BarButtonItem...