Posts

Showing posts from September, 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