Delphi FAQ Page
These FAQs are contributed by you (our online community members). They are organized by our knowledge base topics. Specifically, by the Delphi sub-topics.
|
11 Pascal and Delphi Coding FAQs
Group: Pascal and Delphi Coding
Topic: BDE
|
Q1. I have an application in Delphi 1-7, using BDE. Is there a way that I can upgrade the BDE so the can work with MSSQL 2005 or 2008. They work fine if MSSQL2000 is is used. Am I on a dead end or there is still hope? |
|
Answer: In 2001 or 2002, Borland announced that they were stopping development on the BDE and on SQL Links. That news affected SQL Links users most since SQL Servers change more dramatically than Paradox and dBase do. So, yes, you are in a bad situation.
You could continue with the BDE using the ODBC drivers for MS SQL but most developers switched out BDE/SQL Links for ADO/dbExpress. My suggestion is to take a look at switching out to ADO.
|
Topic: Delphi for Win32
|
Q2. Can I call a DotNet DLL from my Delphi Win32 application? For example, with Delphi 7 or Delphi 2010? |
|
Answer: It's not easy because the .NET RTL resides in a different process. You can wrap up the DotNet DLL into an ActiveX control and call it or have both your app and the DotNet DLL write to the registry, a file, etc. By the way, you CAN wrap up a Win32 DLL in a DotNet DLL and call it from DotNet.
|
Topic: Language Basics
|
Q3. What is the difference between Camel Casing and Pascal Casing? |
|
Answer: Camel casing capitalizes the first character of each word except the first word, it can frequently resemble a camel. Used by many languages including Paradox's ObjectPAL and Java. myAge theBoxCar
Pascal casing capitalizes the first character of each word (including acronyms over two letters in length). TheHtmlCode CAStatePercent
|
|
Q4. What are the benefits of Win32/64 native code such as in Delphi over .Net? |
|
Answer: In general terms, native code offers faster potential performance and a smaller footprint but can be more complex to build. Also, native code does not require .Net's runtime -- Common Language Runtime (CLR).
|
Topic: OOP
|
Q5. What is the difference between private and strict private? |
|
Answer: Private visibility means members are invisible outside of the unit. In OO terms, this is how Object Pascal implements friendly classes (visibility to the private members of another class). To implement true private members in Delphi 1-7, put each class in a separate unit (most developers didn't bother).
Strict Private visibility means that private members within a class are visible ONLY within the class declared. In OO terms, this is true private visibility.
|
|
Q6. What is the difference between Protected and Strict Protected visibility? |
|
Answer: Protected visibility means members are invisible outside of the unit. In other words, protected members are visible to the class they are declared in as well as descendant classes and any class declared within the unit.
Strict Protected visibility means that protected members within a class are visible ONLY within the class declared and to descendant classes. In OO terms, this is true protected visibility.
|
|
Q7. What is a sealed class? |
|
|
|
Q8. Why do I have to specify virtual when creating an abstract method? Why not just abstract? |
|
Answer: For abstract methods, you must specify either regular virtual with the virtual keyword or dynamic virtual with the dynamic keyword. In Delphi for Win32, virtual methods are optimized for speed and dynamic methods are optimized for size. The Delphi help indicates to use virtual for most situations.
It is true that the compiler could make virtual the default and therefore optional but requiring one or the other is consistent with Object Pascal's strong typing.
|
Topic: Using Data
|
Q9. How do you check screen resolution in Delphi? |
|
Answer: Use the Screen variable which is a TScreen. The Screen variable is a TScreen component that represents the screen of the system on which the application runs. By default, applications create a screen component based on information from Windows about the current screen device and assign it to Screen.
For example, put the following code in a button click: MessageDlg( 'screen width = ' + IntToStr( Screen.Width ) + ', screen height = ' + IntToStr( Screen.Height ), mtInformation, [mbOk], 0 );
|
Topic: Using Controls
|
Q10. I have a form with two TEdit components on it. For the OnChange event for both, it clears the contents of the TEdit that is not changing. However, when clearing on TEdit the OnChange fires and clears the other TEdit, this then causes the OnChange in the other TEdit to fire. Fortunately, the second time the OnChange hits the original TEdit, it is already clear and nothing happens.
How can I prevent the circular event firing? |
|
Answer: The simplest way to prevent the circular event firing is to check the form's ActiveControl property. This property indicates which component currently has the focus.
The OnChange event should read as follows: procedure TForm1.EditChange(Sender: TObject);
begin
if TEdit(Sender).Name <> TEdit(ActiveControl).Name then
begin
// do processing
end;
end;
|
|
Q11. How do you specify which color to use with TColorGrid from the samples page? Why isn't it documented? |
|
Answer: Use the public methods ForegroundColor and BackgroundColor. For example, in the OnChange event of a ColorGrid component you could do the following: procedure TForm1.ColorGrid1Change(Sender: TObject); begin Edit1.Font.Color := ColorGrid1.ForegroundColor; Edit1.Color := ColorGrid1.BackgroundColor; end; None of the components on the "Samples" page are documented.
|
|
|