Pascal Newsletter #21
The full source code examples of this issue are available for download.
![]() |
![]() |
Pascal Newsletter #21 - 03-MAY-2001 INDEX 1. A FEW WORDS FROM THE EDITOR 2. PORTING DELPHI APPLICATIONS TO KYLIX - By Peter Pohmann - File Names - File Names, Again - Units - Forms - Windows API Functions - VCL Components - Database Components 3. CONVERTING FROM TFILETIME TO TDATETIME - By Ernesto De Spirito 4. OLD TIMES (I) - Opinion - By H.R Quiroga - A review of the old times - A crucial historical moment. The mid-eighties. - Toy Language 5. REGULAR EXPRESSIONS IN DELPHI - By Ernesto De Spirito - What are regular expressions? - What are they used for? - TRegExpr freeware library - Examples 6. JOB SATISFACTION OF NETWORKING AND IT PROFESSIONALS: A relationship with dispositions and the mediating influence of training. 7. DELPHI ON THE NET - Delphi articles - Technology - Borland news 8. HELP & MANUAL DRAWING ________________________________________________________________________ 1. A FEW WORDS FROM THE EDITOR Are you interested in a stand-alone and true-WYSIWYG help authoring tool that will aid you in creating very good documentation (HLP, HTML and CHM files and printed manuals) quickly and easily? How about having it for FREE? The Help & Manual Drawing is still going on and you can win a REGULAR LICENSE of Help & Manual, including one year of FREE updates. A $199 value! Registrations will close on Monday, 14 May 2001 at 20:00 GMT, so hurry up and ENTER TODAY! The prize is there, just waiting for someone to get it... and that someone might be you! So, what are you waiting for? Help your luck! You can be the winner! http://www.latiumsoftware.com/ec-software/index.php?lang=en You don't have WWW access? You can either use the www4mail service or you can join by email completing the form at the end of this newsletter. Best regards, Ernesto De Spirito eds2004 @ latiumsoftware.com ________________________________________________________________________ JfControls Library. Multi-language. Multi-appearance. Skins. Privileges. More than 40 integrated and customizable components. Impressive GUI. Centralized resources administration. Multiple programming problems solved. For Delphi 3-7 and C++ Builder 3-6. http://www.jfactivesoft.com/ ________________________________________________________________________ 2. PORTING DELPHI APPLICATIONS TO KYLIX - By Peter Pohmann Porting GUI-based applications from Windows to Linux has never been easier. Since Kylix's CLX library is so similar to the VCL in some cases migration is done in a few minutes. Most programs however will need some substantial work. This article covers the most common issues and shows how to resolve them: File Names ---------- The first problem you will be running in are Linux file names. It makes a difference whether it's MyUnit, myunit or Myunit and with Kylix you have to write the unit name correctly in the unit and in the uses directive. Chances are that you have to rename your Pascal files on the file server as well, if you don't want to live with carelessly spelled file names forever. For the Netware server 4.11 we are using in the office, this is a problem. It will not allow to name a file Test but always renames it to TEST internally. So we had to write a little tool that runs on Linux and renames the files via the Samba server. File Names, Again ----------------- If your program works with files (and which one doesn't?), you have to check for all backslashes used as path delimiters, upper and lowercase in file names and extensions and for drive specifications. There are SysUtils functions like ExtractFileName that work correctly on both platforms but not everybody uses them. Other helpers will be available with Delphi 6 such as IsPathDelimiter and IncludeTrailingPathDelimiter. Also, comparing two file names using CompareText might not be such a good idea on Linux systems. Units ----- Part of the CLX units have names with are preceded by a Q. Q stands for Qt which is the Troll Tech library for visual controls used for VisualCLX. CLX forms are found in QForms, Controls becomes QControls and so on. We use the LINUX define to compile against the correct libraries like that: uses {$ifdef LINUX} QForms, QControls, QStdCtrls, {$else} Forms, Controls, StdCtrls, {$endif} System, SysUtils; It is important to have at least one common unit after the endif. If you put the semicolon behind StdCtrls and QStdCtrls the IDE sometimes feels it must append other units within the ifdef. Forms ----- Yes, you can reuse Delphi forms with Kylix. No, it's not a good idea to do it. If you save your form with Delphi 5 in binary mode (put "Text DFM" off in the local menu of the form designer) you will be able to open it with Kylix. But you probably won't like the layout of your controls under Kylix because it seems to work somehow different. This means you have to change it. Furthermore, CLX controls are missing some of the properties VCL controls have, there are different enumeration values, different font names, additional properties. There are not so many differences but the few suffice to make you want to save your Kylix form in a different file. Our preferred procedure is like that: - Save the form in a binary file under Delphi 5. - Copy the *dfm to a *xfm for use in Kylix. - Change {$R *.dfm} to {$ifdef LINUX}{$R *.xfm}{$else}{$R *.dfm}{$endif} in the form's source code unit. - Open the unit and the form with Kylix and adjust the layout to Linux. This way you can reuse your existing forms but you have to maintain two copies. In my opinion it's the best you can do at present. Windows API Functions --------------------- There is only one thing to say to Windows API Functions: Good-bye. Even if the Kylix IDE uses Wine to run on Linux, Kylix applications don't. This is what you will have to do: - Replace Windows API functions by Delphi functions or components wherever possible. You can do this for most of the file management routines for example. - Write a wrapper function to switch between Windows and Linux version using the LINUX define. That is what we have done e.g. for Sleep and LockFile. Linux system functions are to be found in the Libc unit. VCL Components -------------- The good news is that there is a CLX version of most of the commonly used controls and components like TEdit, TStringGrid, TListView, TTimer. But almost all is not all and you will not find e.g. a one-to-one replacement for the TRichEdit control, because it is based on a DLL delivered with Windows. There are two new components called TTextViewer and TTextBrowser that you can use instead but they are quite limited in terms of functionality. There is not much what you can do if a control you need isn't available. Either you manage to get along without, or you wait until a third-party manufacturer offers it or you develop it by yourself. Database Components ------------------- Since Borland has given up the BDE you will miss the TTable, TQuery, TDatabase and TSession components on your Kylix palette. If your application uses them, you have three alternatives to think about: - Switch to MyBase. MyBase is a kind of database surrogate based on XML files that can be accessed via a TClientDataSet component. Because MyBase has neither index files nor does it support multi-user access, it is a solution only for single-user projects with very small database tables. - Switch to dbExpress and use a database server. dbExpress is the new and slim Borland database access layer. Kylix is delivered with dbExpress drivers for MySQL and Interbase (Desktop Developer) and Oracle and DB2 (Server Developer). Drawback: Your application architecture becomes much more complex, your customer will need to have a database server installed and maintained, great parts or your source code have to be changed. - Switch to a BDE-compatible replacement. There are some BDE replacement database engines available under Windows and there is already one for both platforms at the time of this writing. With TurboDB Components you have to convert your BDE table files but you can stay with your application architecture, you have only minimal source code changes and your customers won't even know about your application using a database (http://www.turbodb.de). There are still some more topics like online-help and assembler statements. But I believe the ones listed above are the most common problems so this article gives you a good insight in what will await you when starting to port your Delphi applications to Kylix. ------------------------------------ Copyright (c) 2001 Peter Pohmann <pohmann@dataweb.de> Are you porting your BDE-based Delphi applications to Kylix? TurboDB is a multi-user database engine specially designed for Delphi and Kylix cross-platform development. Usage is very similar to BDE components, so TurboDB is easy to learn. Your free trial version is available at: http://www.turbodb.de ________________________________________________________________________ 3. CONVERTING FROM TFILETIME TO TDATETIME The FindData field of TSearchRec (the record used by FindFirst and FindNext to retrieve directory entries) is another record that among other information (like for example the short and long names of the file) has three fields that represent the creation, last access and last write times (ftCreationTime, ftLastAccessTime, ftLastWriteTime respectively). These three fields are declared as TFileTime, a type that represents 64-bit dates in Coordinated Universal Time (UTC). If you want to convert these values to TDateTime, you can use the following function: uses Windows; function FileTime2DateTime(FileTime: TFileTime): TDateTime; var LocalFileTime: TFileTime; SystemTime: TSystemTime; begin FileTimeToLocalFileTime(FileTime, LocalFileTime); FileTimeToSystemTime(LocalFileTime, SystemTime); Result := SystemTimeToDateTime(SystemTime); end; Sample call: procedure TForm1.Button1Click(Sender: TObject); var sr: TSearchRec; begin if FindFirst(Application.ExeName, faAnyFile, sr) = 0 then begin ShowMessage(DateTimeToStr( FileTime2DateTime(sr.FindData.ftLastWriteTime))); FindClose(sr); end; end; ________________________________________________________________________ 4. OLD TIMES (I) - Opinion - By H.R Quiroga A review of the old times ------------------------- It is said that any technological revolution requires 30 years to become a definitive and daily form of the human life. It has been this way with the television and the telephone. Computing in some of its aspects (as a revolution) seems to be arriving at its thirty years and thus we can assume that it's already taking its definitive form. Since the late eighties, in desktop computing, there hasn't appeared a truly new (original) product that is important outside its operative surroundings, the last one was Access, Microsoft bought it from a French company as I recall, and if we are rigorous it's a sort of visual evolution of the database systems (xBase, for example). We have about 10 years seeing how existing programs only change their version. Even new manufacturers only make new versions of already existing programs. Think about this a little, Star Office and MS-Office come from WordStar, Visicalc (or Multiplan) in the 80s. Programming languages are not new, just evolutions of BASIC, Pascal and C. Internet browsers are as new as the www (which is not really very new). Checking my computer I didn't find any software really original that wasn't dependent of the operating system (FindOrphan, StartupCop for example). The previous introduction comes to collation because I believe Delphi is arriving at its definitive form as an evolution of Pascal. Let's take a look at the past. I don't intend to tell again what many of use already know, I just want to make some curious comments about history. From now on I'll be referring to Delphi as an evolution of Pascal. A crucial historical moment. The mid-eighties. ---------------------------------------------- Lotus 1-2-3, CP/M, PC-AT and the most common language (at the level) of microcomputers: BASIC. Somewhere in the world, in a cold night, a miserable programmer on his knees finished a prayer like this "... and get us rid of BASIC, amen." Then Turbo Pascal appeared. This is the kind things that makes me doubt about the nonexistence of God. Delphi arises as an evolution of Pascal and Pascal is a prototype (like Ada, APL and others) of what has been called a B&D language ("bondage- and-discipline"). The image of an English woman dressed in black with a whip and chains, determined not allow the possibility of leaving certain rules ('right programming') is very clear to understand for those who went thru "BASIC" in the eighties. Turbo Pascal is responsible for the first valid attempt to take out two labels about Pascal: B&D Language and "toy language". Toy Language ------------ As toy languages we understand those languages of educational purpose designed as a test of some theory in computing science. Pascal, as Niklaus Wirth defined it in 1967, was that. In fact, for a long time many people thought that taking Pascal to a general-purpose language was a bad idea. Among them was Brian Kernighan. In 1981, Brian Kernighan wrote a paper titled "Why Pascal is Not My Favorite Programming Language". As far as I know you can look for it in "Comparing and Assessing Programming Languages" of Alan Feuer and Narain Gehani (Prentice-Hall, 1984). There he manifested some interesting things. He was right in at least one: language extensions end with the portability. The fact is that, returning to present times, if it weren't for the limited portability towards Kylix, Delphi isn't portable (yet). Anyway, one of problems he saw were those of the types "string" (an extension that isn't part of standard Pascal), static and global variables, and other evils that OOP has tried to eliminate with quite success. I never programmed in standard Pascal, my first Pascal was Turbo Pascal 2.xx in CP/M, that perhaps was a toy language as Kernighan considered it, but it could get everything that CP/M was able to give (Would it mean that CP/M was a toy?). Nowadays many Delphi programmers come from C and BASIC in their more evolved versions (Visual C++, Visual Basic) and I don't believe that they think of Delphi as something inadequate for general-purpose programming. Clearly, Delphi is more than a superset of Pascal. ------------------------------------ Copyright (c) 2001 H.R Quiroga In the next issue we'll publish the second part of this article. ________________________________________________________________________ 5. REGULAR EXPRESSIONS IN DELPHI What are regular expressions? ----------------------------- Regular Expressions are a way to search and replace patters of text. In a way, these patterns are like using the wildcards '?' and '*' when searching for files, but regular expressions are immensely more powerful than that. In the pattern you can specify whether the string being sought should occur at the beginning or end of the line, which characters are allowed, how many times they can be repeated and many more things. What are they used for? ----------------------- Basically, they are used for three purposes: 1) Powerful text search (and replace) You can use regular expressions for example to search for a specified record in a database in a much more powerful way than using the SQL LIKE operator. 2) Data validation With Regular Expressions you can validate user input to check whether it follows a given format that due to its complexity and variability cannot be checked with masks. For example, you can check whether a string starts optionally with a plus or minus sign, then a sequence of no more than seven digits and optionally a point followed by up to two digits. 3) Data extraction Not only you can check whether a string follows a certain pattern, but you can extract arbitrary parts of the text. For example, for a phone number like '+1 (123) 555-9999' you can extract the country code ('1'), area code ('123') and the local number ('555-9999'). TRegExpr freeware library ------------------------- Want to implement regular expressions in your Delphi applications? A good way to do it is using the TRegExpr library, which is freeware and comes with full source code and is documented in many languages. This library was developed by Andrey V. Sorokin porting the C code from the well-known Henry Spencer's V8-routines (a subset of Perl Regular Expressions) to Object Pascal. The last version of the library is 0.942 and you can get it from "AnSo @ Web" (Sorokin's web site) at: * AnSo @ Web http://anso.da.ru/ http://anso.virtualave.net/ * TRegExpr library http://anso.virtualave.net/regexpr.zip (~284 Kb) * Help files: (42-55 Kb) - Russian..: http://anso.virtualave.net/RegExpRu.zip - English..: http://anso.virtualave.net/RegExpE.zip - Bulgarian: http://anso.virtualave.net/regexpbg.zip - German...: http://anso.virtualave.net/RegExpG.zip - French...: http://anso.virtualave.net/RegExpF.zip - Spanish..: http://anso.virtualave.net/RegExpS.zip Examples -------- The syntax of V8 regular expressions is well documented in the help file and you can also find many sources of documentation in the Internet, so we are not going to enter into that, but just show a couple of examples of the usage of the library: uses RegExpr; procedure TForm1.Button1Click(Sender: TObject); // Validates the email address in Edit1 begin // Warning: this code should not be used to perform actual // email validation. You should check the RFC specification. // This is just a simplification to show the use of ExecRegExpr. if not ExecRegExpr('[\w\d\-\.]+@[\w\d\-]+(\.[\w\d\-]+)+', Edit1.Text) then begin ShowMessage('The email address is not valid'); Edit1.SetFocus; end else ShowMessage('The email address is valid'); end; procedure TForm1.Button2Click(Sender: TObject); // Extracts email addresses contained in Memo1 var RegExpr: TRegExpr; begin // Warning: this code will not extract all valid email addresses. // This is just a simplification to show the use of Exec and Match. ListBox1.Clear; RegExpr := nil; try RegExpr := TRegExpr.Create; if RegExpr <> nil then begin RegExpr.Expression := '[^\w\d\-\.]([\w\d\-\.]+@[\w\d\-]+' + '(\.[\w\d\-]+)+)[^\w\d\-\.]'; if RegExpr.Exec(Memo1.Text) then repeat ListBox1.Items.Add(RegExpr.Match[1]); until not RegExpr.ExecNext; end; except end; RegExpr.Free; end; ________________________________________________________________________ 6. JOB SATISFACTION OF NETWORKING AND IT PROFESSIONALS: A relationship with dispositions and the mediating influence of training. I am a continuing Psychology student at the University of Hull researching the job satisfaction of IT and Networking professionals. As you may well be aware, the IT industry is booming and demand for IT professionals is extremely high. Most organisations naturally wish to improve or maintain job satisfaction, at least for retention reasons if not for other reasons. While traditional job satisfaction theories highlight potential antecedents of job satisfaction, few researchers have applied theories or elements of theories to the domain of IT, an important element of our world economy. I therefore feel that further research is needed in this area. By completing the following questionnaire, you will be helping me and members of the University to further our understanding. You are asked to complete a QUESTIONNAIRE designed to be quick and easily answered. There are four short sections to complete: Part 1 - Core self-evaluations Part 2 - Training Part 3 - Job satisfaction Part 4 - Demographics Your identity will remain entirely anonymous and your data will be held in a secure database. Although we don't ask for you name, please provide your demographic details and the country in which you currently work. To answer all questions takes approximately 10 minutes. You have until 12pm Friday, 04-May-2001. http://www.researchuk.net/ Thank You Martin Lynch m.a.lynch@psy.hull.ac.uk ________________________________________________________________________ 7. DELPHI ON THE NET Delphi articles =============== * Delphi Database Programming Course - by Zarko Gajic Free online database programming course for beginner Delphi developers focused on ADO techniques. Two new chapters have been added in the last two weeks (Chapter 6 "Data modifications" and Chapter 7 "Queries with ADO"). http://delphi.about.com/compute/delphi/library/weekly/aa010101a.htm * Zoom - by Zarko Gajic How to write a Delphi application that is able to zoom in a portion of your desktop screen. http://delphi.about.com/library/weekly/aa120198.htm * Displaying Macromedia Flash .SWF files in your Delphi Application - by Douglas Tietjen http://www.delphipages.com/news/detaildocs.cfm?ID=38 Technology ========== * IBM Breakthrough May Lead to Smaller Computer Chips - by Nicole Volpe Will Silicon Valley become Carbon Nanotubes Valley? http://dailynews.yahoo.com/h/nm/20010426/tc/ Borland news ============ * Borland reports profits for the fourth-straight quarter - by Jennifer Pittman "Borland Software Corp. is bucking the technology-tumble trend — and in a big way." http://www.santacruzsentinel.com/archive/2001/April/27/top/stories/ 1top.htm ________________________________________________________________________ 8. HELP & MANUAL DRAWING If you want to participate in the Help & Manual Drawing you can fill in this form and mail it back to us so we can do the registration for you. You can only register ONCE using a valid email address belonging to you. After you are registered you will receive an email with your number that will play in the Official Lottery of Cordoba that will take place on Wednesday 16-May-2001. You can check the results at http://www.ruta1000.com.ar/sorteos/index2.htm (following the link "ULTIMOS RESULTADOS" under the title "LOTERIA CORDOBA") The data of the winner (number, name, age, occupation and country) will be published in the next issue of this newsletter. Full Name: Email: Company: Job/Position: Business Field: Mark one of the following options: ( ) Software Development ( ) Computer Based Training ( ) IT services ( ) Marketing ( ) Financial services ( ) Other Employees: Mark one of the following option: ( ) Just me ( ) 1-10 ( ) 11-50 ( ) 51-500 ( ) More than 500 Country: Which type of documentation do you create? Mark one option: ( ) WinHelp (.HLP) files ( ) HTML HELP files ( ) WinHelp and HTML HELP ( ) Standard HTML for Internet use ( ) Other documentation Have you found Help & Manual interesting? Mark one option: ( ) No ( ) Little ( ) So so ( ) Quite ( ) Very much Have you been missing any features? (OPTIONAL): Do you use other help authoring tools? ( ) Yes --> Please specify: ( ) No --> Do you plan to use a help authoring tool in the future? ( ) Yes ( ) No ________________________________________________________________________ YOU CAN HELP US We need your help to keep this newsletter going and growing. You can help by referring the newsletter to your colleagues: http://www.latiumsoftware.com/en/pascal/delphi-newsletter.php Or you can help by voting for us in some or all of these rankings to give more visibility to our web site and thus increase the number of subscriptions to this newsletter: http://www.sandbrooksoftware.com/cgi-bin/TopSite2/rankem.cgi?id=latium http://news.optimax.com/delphi/links/links.exe/click?id=70C517ECAE6E http://www.programmingpages.com/?r=latiumsoftwarecomenpascal http://www.top219.org/cgi-bin/vote.cgi?delphi&83 http://top100borland.com/in.php?who=20 http://top200.jazarsoft.com/delphi/rank.php3?id=latium http://213.65.224.200/cgi-bin/toplist.cgi/hits?Id=80 It's just a few seconds for you that REALLY mean a lot to us. ________________________________________________________________________ If you haven't received the full source code examples for this issue, you can get them from http://www.latiumsoftware.com/download/p0021.zip ________________________________________________________________________ This newsletter is provided "AS IS" without warranty of any kind. Its use implies the acceptance of our licensing terms and disclaimer of warranty you can read at http://www.latiumsoftware.com/en/legal.php where you will also find a note about legal trademarks. Articles are copyright of their respective authors and they are reproduced here with their permission. You can redistribute this newsletter as long as you do it in full (including copyright notices), without changes, and gratis. ________________________________________________________________________ Main page: http://www.latiumsoftware.com/en/pascal/delphi-newsletter.php Group home page: http://groups.yahoo.com/group/pascal-newsletter/ Subscribe/join: pascal-newsletter-subscribe@yahoogroups.com Unsubscribe/leave: pascal-newsletter-unsubscribe@yahoogroups.com Problems with your subscription? eds2004 @ latiumsoftware.com ________________________________________________________________________ Latium Software http://www.latiumsoftware.com/en/index.php Copyright (c) 2001 by Ernesto De Spirito. All rights reserved. ________________________________________________________________________ |
The full source code examples of this issue are available for download.
![]() |
Errors? Omissions? Comments? Please contact us!






