-
Different function parameter modifiers in Delphi
Posted on August 2nd, 2010 6 commentsRecently a friend asked me about constant parameters in Delphi functions, that brought the idea of writing a new post about passing parameters to functions/procedures in Delphi.
Parameter modifiers
When you call a function or procedure (I am going to refer to both of them as Functions here), you have to somehow pass the required input or output parameters to it. Parameters are passed to functions either by value, or by reference.
Passing by value means, compiler makes a new copy of the original data, and sends it to the function. This way, the function has its own copy of data, and changing value of the parameter inside the function does not affect the original data. This is the default mode when you pass a parameter to a function in Delphi: Read the rest of this entry »
-
ProcessInfo 1.3 is released
Posted on July 26th, 2010 2 commentsHi,
ProcessInfo 1.3 is released. The changes in this release are:
- CPU usage is added to TProcessItem.
- Is64Bit is added to TProcessItem.
- IsAccessible is added to TProcessItem.
- Setting thread priority is added to TThreadItem.
- Setting process base priority class is added to TProcessItem.
To download ProcessInfo 1.3, please go to ProcessInfo page.
-
How to use TProcessInfo #2
Posted on July 26th, 2010 No commentsI had a few e-mails and comments about using TProcessInfo, so I decided to answer those questions in new blog posts.
Q1: How can we find a module which is running a specific thread, giving a thread ID:
A: First of all, Threads are not assigned to modules, they are assigned to processes. You can find a process which is running the thread, by searching in the list of threads owned by each running process. Here is a sample code:
function FindProcessByThreadID(ID: Cardinal): TProcessItem; var ProcessInfo : TProcessInfo; AProcess : TProcessItem; begin Result := nil; ProcessInfo := TProcessInfo.Create(nil); try for AProcess in ProcessInfo.RunningProcesses do begin if Assigned(AProcess.Threads.FindByID(ID)) then begin Result := AProcess; Exit; end; end; finally ProcessInfo.Free; end; end;FindProcessByThreadID iterates over all running processes, and checks which of them has a thread with the given ID. If a process owns a thread with that ID, it will return that process as a TProcessItem object.
Once you have the process object, you can get more information about the process or the specific thread, or you can kill the process, or suspend the thread. For example:
var Process : TProcessItem; begin Process := FindProcessByThreadID(StrToInt(3444)); if Assigned(Process) then ShowMessage(Process.FullPath); end;The above code looks for a thread with its ID = 3444, and if it is found, it provides full path of the EXE file for that process.
Q2: How can we get memory consumption for a given process?
A: You can read memory info for a given process using TProcessItem.MemoryInfo. It provides different info about the memory the process is consuming. Here is an example for reading memory info of Google Chrome process while it is running :
var ProcessInfo : TProcessInfo; AProcess : TProcessItem; begin ProcessInfo := TProcessInfo.Create(nil); try AProcess := ProcessInfo.RunningProcesses.FindByName('Chrome.exe'); if Assigned(AProcess) then ShowMessage(Format('WorkingSet Size = %d, Peak WorkingSet Size = %d', [AProcess.MemoryInfo.WorkingSetSize, AProcess.MemoryInfo.PeakWorkingSetSize])); finally ProcessInfo.Free; end; end;First we search for Chrome.exe process among running processes. Once the process is found, we read its current working set size, and pick working set size through MemoryInfo property, and show them in a message box. The values returned are in Bytes.
Q3: How can we get process base priority class or change it?
A: You can access base priority class for a given process or modify it (added in version 1.3), using TProcessItem.
PriorityClassBase. Be careful, adjusting a base priority class of a given process inappropriately might make other processes unresponsive! Here is a example code:
var ProcessInfo : TProcessInfo; AProcess : TProcessItem; begin ProcessInfo := TProcessInfo.Create(nil); try AProcess := ProcessInfo.RunningProcesses.FindByName('firefox.exe'); if Assigned(AProcess) then AProcess.PriorityClassBase := BELOW_NORMAL_PRIORITY_CLASS; finally ProcessInfo.Free; end; end;You can also change each priority of each thread within a process by setting BasePriority property of that TThreadItem instace.
Q4: How can I check if a process is 64-bit?
A: You can check this by reading TProcessItem.Is64Bits property.
Q5: How can I get CPU usage for a given process?
A: You can get CPU usage by reading TProcessItem.CPUUsage property.
I hope these few answers and sample source codes can help you use Process Info. For other examples of using Process Info, please refer to this post: How to use TProcessInfo
If there is any question regarding using Process Info, or anything about Delphi that you think worth being mentioned in Tips & Tricks section of this website, please contact me, and let me know about it.
Have Fun!
-
Embarcadero and Iran Embargo
Posted on May 26th, 2010 5 commentsAre you an Iranian Delphi (or C++ Builder, or JBuilder) developer? Have you noticed that while you are in Iran, some pages of Embarcadero website do not load?
You might have thought it is your ISP, or maybe Iranian filtering system, or maybe your browser, which are causing the problem, because other visitors are using the website with no such problems, and nobody has reported such problems. Well, if you thought that way, you are wrong!
It was some months (or maybe a year) ago that I noticed I cannot log into Embarcadero forums (web interface for their newsgroups). It was telling me that my username\password was not valid! I retried my username\password several times, and even tried to make it to email me my password, but no success! Eventually I decided to create a new username, and tell them about my problem in the forum, but when I was creating the new account, I noticed that Iran is not in Countries list, and I have to choose another country if I want to create an account in their website. It was there that I found out they deleted my previous forum ID without any notification just because Iran was chosen as my country!
Days passed and April 2010 came, I noticed that some Iranian Delphi developers were reporting problems about accessing EDN (Embarcadero Developers Network). EDN provides some articles, news reports, and white papers about Embarcadero products for software developers. I thought it must have been some ISP problems, but since I wasn’t sure, I created a topic in Embarcadero forums, and asked if EDN is down. Some users mentioned they have no problem accessing it in Europe, and later on, my topic got deleted from their forum, and I received an email from one of Embarcadero employees that this is due to their respected company’s policies in complying with US embargo, and I should keep it as a confidential note!
Now it’s been some days (maybe 1 or 2 weeks) that I found out accessing weblogs belonging to Delphi team members on Embarcadero website, and also documents wiki website (online version of Delphi documentation) is not possible from Iran. Read the rest of this entry »
-
My View on New Delphi Roadmap
Posted on May 13th, 2010 1 commentEmbarcadero published a new roadmap for Delphi on May 10. You can see the new roadmap here.
I don’t know if we can call it a roadmap or not. It does not give any time schedule or estimation on when each mentioned feature might be available (except a rough estimation for 64-bit compiler preview availability in the first half of 2011). To me, the published roadmap does not clear any ambiguity regarding Delphi future. It just adds more to it! Really, what was the purpose of publishing this?! Maybe just to muffle those Delphi users who were complaining about not having any updated roadmap.
Now, let’s take a look at this so-called roadmap…
-
ProcessInfo 1.2 is released
Posted on January 13th, 2010 1 commentHi,
ProcessInfo 1.2 is released. The changes in this release are:
- SuspendThread, ResumeThread, TerminateThread methods are added to TThreadItem class. Now you can pause/resume/terminate any running thread in a given process.
- TProcessInfo.Active and TAppInfo.Active are published properties, and can be set in design mode.
- TProcessInfo.RunningProcesses and TAppInfo.RunningApplications automatically populate the corresponding list if UpdateList method is not called yet. This means even if you don’t activate any of these two components, or call their UpdateList method, accessing RunningProcesses or RunningApplications does not cause Access Violation.
To download ProcessInfo 1.2, please go to ProcessInfo page.
Regards.
-
Component Toolbar slows down RAD Studio 2010
Posted on January 2nd, 2010 4 commentsIn RAD Studio 2010 there is a new IDE feature called Component Toolbar. This feature provides a component palette similar to the old Delphi component palette.
This toolbar provides a nice search box which is able to filter components in the palette based on the search phrase. This toolbar is disabled by default, and is shown when Classic Layout is selected. Here you can see a snapshot of Classic Layout in RAD Studio 2010:
A few weeks ago while I was working with Delphi 2010, I noticed a delay when switching from code view to form designer. The delay was there not only in the complex forms, but also in simple empty forms! It was not a big delay (about 1 second), but since I had to switch between code and form designer view many times, it was really annoying, so I decided to investigate it and find out what is causing this delay.
-
Chad Hower of Indy fame is arrested!
Posted on November 7th, 2009 No commentsToday I saw a new blog post on Kudzu(Chad Hower)’s RSS feed, with this weird title: “Arrested in Bulgaria on False Charges”
At first I thought it is just a joke, but then I realized it isn’t
It seems Chad is in trouble for his son’s custody. He’s been accused of kidnapping his own son and traveling to Bulgaria with him in 2006!Anybody having some experiences with Delphi programming knows Chad, and his great open-source project; Indy Project.
I hope his problem is solved soon. He asked for help, and I think all Delphi developers who are using Indy have to at least spread the word, or if they can, help him financially to get out of this trouble.
-
ProcessInfo 1.1 is released
Posted on October 22nd, 2009 1 commentHi,
I released a new version of ProcessInfo. In this release I added these features:
- Enumerators are added for Windows, Threads, Modules, and Processes; Now you can use for-in statements in D2007 and above for iterating on running processes list, or modules\threads\windows of a given process.
- TProcessItem.UserName is added; This property returns domain name\user name which is running the process.
- TProocessInfo.AdjustDebugPrivilage is added; This method is called automatically.
TThreadItem.ToString & TProcessItem.ToString are added; TThreadItem.ToString returns ThreadID. TProcess.ToString returns process EXE name. - Now supports Delphi 7,2007,2009, 2010; Some conditional compiler directives are added so that it can be used in D7, 2007, 2009, and 2010. I tested it in D7, 2009, and 2010. It should work in D2007 too.
To download ProcessInfo 1.1, please go to ProcessInfo page.
Regards.
-
How to use TProcessInfo
Posted on September 11th, 2009 5 commentsThe other day I published Process Info component pack which contains TProcessInfo and TAppInfo. A sample task manager was also published as demo.
I thought maybe it is a good idea to talk about these components and some of their usages by providing some sample source codes. So I will start with TProcessInfo.



