Thursday, June 10, 2010

How to get Delphi 7 to work in Windows 7 ?

CCH : Quoted verbatim from http://weblog.hansotten.com/?p=833

As you can see in this blog, I recently started programming again in Pascal, eh, Delphi Object Pascal. The version I use (since it is the last version close to traditional Windows programming) is version 7.

The best version to use  is the version that floats around as Delphi 7.2 Second Edition (search a torrent site) which is a trimmed and bugfixed small package.

Of course this package runs fine on Windows XP. But how on Windows 7?

This is how I got it to work.
Installation
  • Make sure you run this as administrator,  you will need the privs.
  • Run the Delphi installer. Use defaults for the file locations, ignore the incompability warnings.
  • Dont start Delphi 7 as it will complain when starting a project  about unable to rename delphi32.$$$ to .dro in the /program files/delphi directories . And something about debug options requiring a change.
    So there are access problems, as to be expected. Windows 7 is a lot more robust, so directories are better protected.
Solve the access problems
  1. Run this as administrator.
  2. Open the properties on c:/program files/delphixxx directory.
  3.  On the first tab Clear the Read-only attribute and press Apply for all files including subdirectory.
  4.  Open the security tab
  5. Give users (and admins if necessary) full access to  c:/program files/delphixxx directory   
Now Delphi can be used to write programs again.

Fix Winhelp
Help does not function, a windows pops up telling “winhelp is not supported anymore on this Windows version, go to microsoft.com for a fix” .
The fix for Vista is already made, the Windows 7  fix will be here Real Soon Now.

Edit january 2010:  Search ‘ Windows Help program (WinHlp32.exe) for Windows 7′ on microsoft.com, currently here ,  install that and you do not need the next trick.
So this will be fixed in the future, but for now it can be solved as follows.
  1. Remove the Read-only attribute from winhlp32.exe and winhelp32.exe in c:/windows
  2. Set  ownership of the winhlp32.exe file (properties, security tap, advanced)  to administrators (and remember, you are logged on as admin!)
  3.  change the security to full control
  4.  rename winhlp32.exe to something like winhlp32old.exe just in case
  5. copy from a Windows  XP system the files winhlp32.exe and winhelp.exe in c:\windows
Now help functions also.

Sunday, October 18, 2009

Place a Progress Bar Inside a Standard MessageBox in Delphi Apps by Delphi.About.Con

Friday October 16, 2009
in Delphi TIPS :: Let's say you have a standard Windows dialog box displaying a question to the user with "Yes" and "No" (confirm) buttons. Wouldn't it be great if a progress bar could be displayed within a dialog box "counting" seconds until the dialog box automatically closes itself?
Read the full article to learn how to Place a Progress Bar Inside a Standard MessageBox in Delphi Apps



Let's say you have a standard Windows dialog box displaying a question to the user with "Yes" and "No" buttons. Wouldn't it be great if a progress bar could be displayed within a dialog box "counting" seconds until the dialog box automatically closes itself?

  1. We first create a dialog using CreateMessageDialog
  2. This function will return a form object with dialog
  3. In this object we can add a ProgressBar
  4. We also add a Timer object for dynamic progress bar position update
  5. Show dialog using ShowModal
  6. Handle the OnTimer event of the TTimer component to see if the elapsed number of seconds has passed - if so, we close the dialog by setting the ModalResult property, from code, to mrCancel.
  7. If not, we use StepIt to update the progressbar.
Drop a TButton (Button1) on a form (Form1), and try the next code:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;
var
   AMsgDialog : TForm;
   AProgressBar : TProgressBar;
   ATimer : TTimer;
begin
   AMsgDialog := CreateMessageDialog('Quickly! Answer Yes or No!', mtWarning, [mbYes, mbNo]) ;
   AProgressBar := TProgressBar.Create(AMsgDialog) ;
   ATimer := TTimer.Create(AMsgDialog) ;
   with AMsgDialog do
   try
    Tag := 10; //seconds!

    Caption := 'You have 10 seconds';
    Height := 150;

    with AProgressBar do begin
     Name := 'Progress';
     Parent := AMsgDialog;
     Max := AMsgDialog.Tag; //seconds
     Step := 1;
     Top := 100;
     Left := 8;
     Width := AMsgDialog.ClientWidth - 16;
    end;

    with ATimer do
    begin
     Interval := 1000;
     OnTimer:=DialogTimer;
    end;

    case ShowModal of
     ID_YES: ShowMessage('Answered "Yes".') ;
     ID_NO: ShowMessage('Answered "No".') ;
     ID_CANCEL: ShowMessage('Time up!')
    end;//case
   finally
    ATimer.OnTimer := nil;
    Free;
   end;
end;


//make sure you add this function's header in the private part of the TForm1 type declaration.
procedure TForm1.DialogTimer(Sender: TObject) ;
var
   aPB : TProgressBar;
begin
   if NOT (Sender is TTimer) then Exit;

   if ((Sender as TTimer).Owner) is TForm then
   with ((Sender as TTimer).Owner) as TForm do
   begin
     aPB := TProgressBar(FindComponent('Progress')) ;

     if aPB.Position >= aPB.Max then
       ModalResult := mrCancel
     else
       aPB.StepIt;
   end;
end;

Monday, October 5, 2009

New MDI Child Forms By Zarko Gajic, About.com

If you are creating MDI applications using Delphi, you must have noticed some "quirks" or issues that you cannot simply handle / fix from your code.
MDI interface was designed in the days of Windows 3 (some 10+ years ago) and it was designed with a single type of application in mind: a parent window that hosts multiple instances of the same class of "document" window (just think of you first MS Word).

 

Nasty MDI Child Resizing Animation

When creating (to show) an MDI child an animation of resizing will take place. This animation might look ugly if the code executed during the creation of your MDI child takes some time to process. Even if WindowState property was set to wsMaximized when an MDI child is created it will be created using Default Pos at X, Y coordinates where you left your form at design time.
Windows simply insists on creating MDI children visible and at a default position.
After creation, the MDI child will get maximized but an ugly animation will take place.

 

Quickly Create MDI Children - Eliminate "Create & Resize" Animation

To eliminate the MDI child creation and resizing animation you can send a special message to the MDI parent form, WM_SETREDRAW. The WM_SETREDRAW can be sent to a window to enable changes in that window to be redrawn or to prevent changes in that window from being redrawn. To prevent the animation flicker, have the next code in your MDI Parent form's unit:
TMDIMainForm = class(TForm)
private
  fLockClientWindowUpdateCount: Integer;
public
  constructor Create(aOwner: TComponent) ; override;
  procedure LockClientWindowUpdate;
  procedure UnlockClientWindowUpdate;
end;

...

constructor TMDIMainForm.Create(aOwner: TComponent) ;
begin
  inherited Create(aOwner) ;
  fLockClientWindowUpdateCount := 0;
end;

procedure TMDIMainForm.LockClientWindowUpdate;
begin
  if fLockClientWindowUpdateCount = 0 then SendMessage(ClientHandle, WM_SETREDRAW, 0, 0) ;
  Inc(fLockClientWindowUpdateCount) ;
end;

procedure TMDIMainForm.UnlockClientWindowUpdate;
begin
  Dec(fLockClientWindowUpdateCount) ;
  if fLockClientWindowUpdateCount = 0 then
  begin
    SendMessage(ClientHandle, WM_SETREDRAW, 1, 0) ;
    RedrawWindow(ClientHandle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN or RDW_NOINTERNALPAINT)
  end
end;
Now, when you need to create (and show) an MDI client form(s), just call LockClientWindowUpdate and UnlockClientWindowUpdate. If a client window takes some time to create, you can change the cursor to let the user something (form creation) is going on:
LockClientWindowUpdate;
Screen.Cursor := crHourGlass;
try
  Application.CreateForm(MDIChildForm) ;
finally
  Screen.Cursor := crDefault;
  UnlockClientWindowUpdate;
end;
That's it. Now your MDI child forms will load faster and without the confusing animation.

Sunday, October 4, 2009

SQL Server Data Access Components Overview

CCH : From http://www.devart.com/sdac

SQL Server Data Access Components (SDAC) is a library of components that provides access to Microsoft SQL Server databases. SDAC connects to SQL Server directly through OLE DB, which is a native SQL Server interface. The SDAC library is designed to help programmers develop faster and cleaner SQL Server database applications.
SDAC is a complete replacement for standard SQL Server connectivity solutions and presents an efficient alternative to the Borland Database Engine for access to SQL Server.

SDAC Palette

Advantages of SDAC Technology

SDAC is a direct connectivity database wrapper built specifically for the SQL Server server. SDAC offers wide coverage of the SQL Server feature set and emphasizes optimized data access strategies.

Wide Coverage of SQL Server Features

By providing access to the most advanced database functionality, SDAC allows developers to harness the full capabilities of the SQL Server and optimize their database applications. SDAC provides complete support of working with SQL Server 2005 Compact Edition, Service Broker technology, the IRowsetFastLoad interface, working with metadata information, and MARS.

Optimized Code

The goal of SDAC is to enable developers to write efficient and flexible database applications. The SDAC library is implemented using advanced data access algorithms and optimization techniques. Classes and components undergo comprehensive performance tests and are designed to help you write high-performance, lightweight data access layers.

Compatibility with Other Connectivity Methods

The SDAC interface retains compatibility with standard VCL data access components like BDE. Existing BDE-based applications can be easily migrated to SDAC and enhanced to take advantage of SQL Server-specific features. Project migration can be automated with the BDE/ADO Migration Wizard.

How Does SDAC Work?

SDAC allows you to connect to SQL Server through OLE DB, which is the lowest documented SQL Server interface.
SDAC connects through OLE DB through a set of COM-based interfaces. SDAC is designed to be lightweight and consists of a minimal layer between your code and SQL Server databases.
In comparison, the Borland Database Engine (BDE) uses several layers to access SQL Server, and requires additional data access software to be installed on client machines.
The BDE data transfer protocol is shown below.
BDE Connection Protocol BDE Connection Protocol
SDAC allows you to avoid using BDE and DBLibrary.
SDAC Connection Flow SDAC Connection Flow

Key Features

The following list describes the main features of SQL Server Data Access Components.
  • Direct access to server data. Does not require installation of other data provider layers (such as BDE and ODBC)
  • VCL, VCL.NET, and CLX versions of library available
  • Full support of the latest Microsoft SQL Server versions, including Express and Compact Editions
  • Support for all SQL Server data types
  • Disconnected Model with automatic connection control for working with data offline
  • Local Failover for detecting connection loss and implicitly reexecuting certain operations
  • All types of local sorting and filtering, including by calculated and lookup fields
  • Automatic data updating with TMSQuery, TMSTable, and TMSStoredProc components
  • Unicode support
  • Support for many SQL Server-specific features, such as MARS and bulk copy operations
  • Advanced script execution with TMSScript component
  • Support for using macros in SQL
  • Easy migration from BDE and ADO with Migration Wizard
  • Lets you use Professional Edition of Delphi and C++Builder to develop client/server applications
  • Includes annual SDAC Subscription with Priority Support
  • Licensed royalty-free per developer, per team, or per site


SDAC Design-Time View

SQL Data Access Components design time

Old Delphi Applications More Compatible with Windows 7 -Marco Cantu - 2nd Oct 2009

I've noticed that Windows 7 is more compatible with old Delphi applications than Vista is. Here are two cases I found.

I've noticed that Windows 7 is more compatible with old Delphi applications than Vista is. Here are two cases I found (mostly while giving my talk on Windows 7 at EKON last Tuesday).

The first relates with the preview of the application main form available in Windows Flip (the task bar preview), Windows Flip 3D, or even the plain list of windows you obtain using Alt+Tab keys. In Vista, a traditional Delphi application would have been represented by its icon when it was minimized and displayed in any of these views1. The fix came to the VCL in Delphi 2007 with the MainFormOnTaskbar property of the TApplication class. In Windows 7, however, a traditional Delphi application would show properly in the various previews, even when minimized. This basically means that the MainFormOnTaskbar property becomes much less relevant, although it will still affect the title displayed for the application in the taskbar. With older versions of Delphi, or in case the property is set to False, the title will match the Title property of the Application global object; on the other hand, if MainFormOnTaskbar is set to True, the title is the Caption of the main form.

Another relevant changes relates with the behavior of Windows Resource Protection and the Virtual Storage (the area created for each user to host the document and configuration files that old “non-themed” applications save in Program Files sub-folders or in the Windows folder). Windows 7 expands the virtual storage area to include the root of the C: drive2. As an example, the FileAccess program discussed in my “Delphi 2007 Handbook” tried to save a file to the root of the C: drive with the code: "Memo1.Lines.SaveToFile ('C:\SomeText.txt');". In Vista this code used to fail with an error both for a themed and a non-themed application, in Windows 7 the themed application succeeds and saves the file to the basic folder of the virtual storage area, which on my computer (for my account) is: C:\Users\Marco\AppData\Local\VirtualStore.

So, with all fanfare saying you have to move to .NET to build Windows applications, Microsoft is putting extra effort to let old Delphi (and I suspect, Visual Basic 6) programs work better with the latest version of their operating system. Maybe I missed other extended compatibilities (or incompatibilties) between Delphi programs and Vista, fell free to share others on the blog or email me.

PS. Delphi 2010 offers native support for a number of interesting new features of Windows 7, covered in my talk and part of my coming "Delphi 2010 Handbook". These are all native or COM libraries, so no .NET required either. But that's a different story.

Marco Cantu
2nd October 2009

Saturday, October 3, 2009

Delphi Basics : Using Inheritance in Dephi 7 - A Simple Example

1. Create a Standard Form as the Ancestor Form.




In the above example, I have added a InfoPower TwwDBNavigator,TwwDBGrid controls as well as a ADODataset and a DataSource all duly connected to each other.

2. Select File/New/Others to get the following Dialog


3. Click OK to get the inherited Form StdViewForm1 which looks exactly like the form that we created in (1) above.



4. Then, just adjust the command text property to read from another table and bingo, you have another module ready to go. Then just select File/Save As and add it to the menu item of your choice. That's it !

Friday, October 2, 2009

DevExpress: How to Manually Install Developers Express into Delphi 5 ?

In an earlier article, I had written about Developers Express's decision NOT to support D5 anymore. So what happens when you install the latest DevExpress into D7. Simple, it kills off your existing installation of DevExpress  in D5.

So what to do ?

No worries, here is how you can manually install any prior verion of DevExpress into D5. Use File/Open to open  & recompile in the suggested order as below :-

1) XP Theme Manager - dxThemed5.dpk (RTL)
2) Xpress Common - dxComnd5.dpk (RTL)
3) Express GSI + Lib (dxGDIPlusD5.apk)
4) CxLibrary - cxLibmyclD5.dpk (RTL)
5) As for dxComnD5.dpk (need also to click Intall)
4) ExpressBars (need to recompile and install 2+2 dpk)


Update on 3rd October 2012 

Another way to have the latest version (#59) Developer Express components updated in D7 without killing off the version installed in D5 is really simple. Just create another User Name in Win7 and installed the latest version :-)

Welcome to Delphi... Delphi... Delphi

I have been a Delphi Developer since Delphi 3 when I finally decided on Delphi in 1996 as my programming language of choice for the Windows 32 environment. So what have I created with Delphi ?

Would you believe that I had single-handedly created a full ERP2 system comprising ERP+CRM where ERP=Sales Distribution+MRP+ Procurement Management+Planning & Production +Finacial Management + Human Resources Management System.

Since 15th February 2009, we have visitors from more than 60 countries including Malaysia, United States, Brazil, Italy, Australia, India, Turkey, Russian Federation, Spain, Indonesia, Hungary, South Africa, Germany, Mexico, Argentina, Singapore, Saudi Arabia, Colombia, Czech Republic, Canada, France, Croatia,Thailand, Bulgaria, Slovenia, Hong Kong, Poland, Sri Lanka, Chile, Japan, Austria, Ukraine, Azerbaijan, Ireland, Tunisia, Greece, Taiwan, Egypt, Bolivia, Paraguay, Iran, Islamic Republic , Morocco, Angola, Belgium, Portugal, Norway, Venezuela, United Arab Emirates, Algeria, Korea, Republic Of, Slovakia, Georgia, Lebanon, Macedonia, Sweden, Philippines, Vietnam, Dominican Republic