Posts

Showing posts from 2017

Move a border less form in Delphi

We usually use mouse to drag the windows form title bar to move the window on our desktop. But what if we required to move a border less form and that also does not have title bar. So here are some solutions to move a border less form in Delphi. There is a new way to move the  form by just dragging on any point in the form itself. This is ideally suitable for those form that don't have title bar. For example, FormStyle := bsNone; Use the following code to drag on window content and you able to move the form just as you drag on title bar: type   TForm1 = class(TForm)   private     procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHitTest;   end; procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest); begin   inherited;   if Msg.Result = htClient then     Msg.Result := htCaption; end; The above code attempt to hijack the mouse event to tell the system to treat the mouse click action on windows client area when user click on wind

TStringlist Name Value pair

TStringlist Delphi provides TStringlist class to main list of strings easily. We can store, delete, find and sort list of string in a TStringlist object. With this blog I guess you have some idea and used TStringlist. But TStringlist provides a distinct feature that allows to store Name and Value pair as a list item at a same time like 'James=1' in which James=Name and 1=Value. And some TStringlist properties or methods used for Name and Value pair are... NameValueSeparator  A symbol character that used to differentiate Name and Value in the pair Ex.. James=1 = is NameValueSeparator Names Store list of Names in a string list like  JAMES,  KYRA,  PETE, RUHI, SUNNY Values Store list of Values assigned to Names in a string list like 1,2,3,4,5 How to add to Stringlist? slStudent.Add('James=1');  // Jame as Name, = as NameValueSeparator, 1 as Value // IndexOfName  Returns Index of Name stored in TStringlist  when using name/

exception ERegistryException with message 'Invalid data type for 'Anykey''

This exception generally raises during reading a Window Registry key value in Delphi.  This exception raises when Type of stored value in Windows register is different from the type that  we used for reading the registry value in Delphi.  We mostly get this error for  Binary Type( rdBinary ) data.  For this check if key values exists before do Read and check for data type too (if is compatible with ReadBinaryData)... ... if reg.ValueExists(Key) then     if reg.GetDataType(Key) = rdBinary then Or  You can do following rundown to solve this issue - Close you program - Open regedit - T hen Under File,click Export and keep a backup of systems registry - Under "Edit" Tab. Go to Find and type the Key - Delete the Key if found and continue till finish. - Then restart your program again and it should work. Or if the data type is  REG_DWORD  then try to read/write data using  ReadInteger()/Write Integer() functions.  ReadInteger() is the correct way to read

ORA-01745: invalid host/bind variable name ERROR in Delphi when we use Oracle DB

I received the above error message when TADOQuery.Open method is called. I checked the SQL of TAdoquery component which looked fine to me but was still getting errors. SQL was as follow AdoQuery1.Sql.text := 'SELECT * FROM EMPLOYEE E WHERE E.JOINDATE < :DATE'; AdoQuery.Open; //---ABOVE ERROR RAISED----// After researching the issue, I found that the  issue is with :DATE parameter that I have used in SQL. A pparently the word "DATE" is a reserved word in Oracle, and therefore cannot be used as a SQL parameter or bind variable name.  You can not use a key word as parameter name.  So I replaced the :DATE parameter with :JDATE in SQL as follow and it worked fine without any error. AdoQuery1.Sql.text := 'SELECT * FROM EMPLOYEE E WHERE E.JOINDATE < :JDATE'; AdoQuery.Open;   // ---ERROR RESOLVED----// So please note* that you should not use any reserve keywords as  parameter while writing SQL in Delphi side. Some of the common Ora

How to get WINDOWS special directories path in Delphi?

Sometime we need some special directories path from Microsoft Windows system to store User data or to copy some files etc.  So we can get those folder paths in Delphi in several ways. In this blog I have tried to cover all the ways.  If I have left something please feel free to add comments. By using Windows API function SHGetFolderPath  Delphi provides SHGetFolderPath API function which helps us to get windows system folder paths. We need to use  ShlObj unit in uses clause. For more details about SHGetFolderPath please visit following link SHGetFolderPatch Here at following I have created a string function  GetSpecialFolderPath  using SHGetFOlderPath API function which will return all special Windows folder path as per  CSIDLFolder value. function GetSpecialFolderPath(CSIDLFolder: Integer): string; var    FilePath: array [0..MAX_PATH] of char; begin   SHGetFolderPath(0, CSIDLFolder, 0, 0, FilePath);   Result := FilePath; end; // to get DESKTOP folder l

How to debug your Delphi application code? / Debugging in delphi

Image
Once you compile a program in Delphi and run it, you may think you’re finished,  but not all of your problems may be solved. Programs can have run-time errors, or they  may not work as you planned. When this happens, you will need to discover what has  gone wrong and how to correct it. So Debugging is the process of finding and resolving of bugs or error in a computer software.  While working with Delphi One of the things we should learn is debugging a Delphi application. Now a days every high level programming  languages provides advanced debugging tools that helps to find the exact reason of the problem. Delphi also includes an integrated debugger in IDE. In this blog I will explain some nice features in Delphi which will help you to debug your programs. Settings required to debug codes... Project options Before we start using the Delphi debugger tools, we have to make sure all necessary settings are set from Project->Options menu.  After open Option dialog, do the

Multi Threading in Delphi

Image
What are threads? and why we use them? Earlier days of programming all programs were single threaded and single tasking in which your program will ran exclusively on the machine  or not at all. With increasingly sophisticated applications and increasing demands on personal computers, now multiprocessing and multithreading  operating systems are available. Multithreading on computer programming was mainly required for better performance and usability. So first lets go about Process , Process is a program that runs on a system and uses system resources like CPU, Memory etc. And every process has  a main thread. In a Process many actions can be performed one by one on fast in fast perform order. And Thread is generally used to perform several  set of actions at once in situations like some actions may cause a considerable delay  but during that period the program should be able to perform other actions too. For an example in windows explorer we are copying a large volume  of data