Archive
CPUInfo via WMI
This example demonstrates how to retrieve processor information by using Windows Management Instrumentation. This example I created as my response to a subject posted in Delphi Indonesia Forum titled ngebaca s/n processor dgn delphi. For a complete source code, you can donwload it from Delphi Indonesia Forum (onDownload section).
{ CPUInfo, An attempt on CPU information retrieval using Windows Management Instrumentation (WMI) Copyright (c) 2005 Bayu Prasetio This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. The current web address of the GNU General Public License is: http://www.gnu.org/licenses/gpl.html You can contact the authors of this software at: bpras@bprasetio.or.id ------------------------------------------------------------------------------ Portions of the code are belong to Comprehensive Open Source Benchmarking Initiative (COSBI) authors and its contributors, copyright COSBI Team. For further information about COSBI please refers to http://www.flickerdown.com/osmark/ or http://www.cosbi.org } unit uMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, ValEdit, WbemScripting_TLB, ActiveX, ComCtrls, XPMan; type TfrmMain = class(TForm) vleCPUInfo: TValueListEditor; stbMain: TStatusBar; XPManifest1: TXPManifest; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } FLocator : TSWBEMLocator; FSinkClasses : TSWbemSink; procedure RetrieveCPUInfo; public { Public declarations } end; var frmMain: TfrmMain; implementation {$R *.dfm} { TfrmMain } procedure TfrmMain.FormCreate(Sender: TObject); begin FLocator := TSWBEMLocator.Create(nil); FSinkClasses := TSWBEMSink.Create(nil); RetrieveCPUInfo; end; procedure TfrmMain.FormDestroy(Sender: TObject); begin FSinkClasses.Free; FLocator.Free; end; procedure TfrmMain.RetrieveCPUInfo; var lServices : ISWbemServices; lObjectSet : ISWbemObjectSet; lSObject : ISWbemObject; lPropSet : ISWbemPropertySet; lSProp : ISWbemProperty; propEnum : IEnumVariant; Enum : IEnumVariant; tempObj : OleVariant; Count : Cardinal; Value : Cardinal; sValue : String; begin Screen.Cursor := crHourGlass; try FSinkClasses.Cancel; // connect to local and use root\CIMV2 namespace lServices := FLocator.ConnectServer('', 'root\CIMV2', '', '', '', '', 0, nil); // retrieve the Win32_Processor information lObjectSet := lServices.ExecQuery('SELECT * FROM Win32_Processor', 'WQL', wbemFlagReturnImmediately, nil); Enum := ( lObjectSet._NewEnum ) as IEnumVariant; while (Enum.Next(1, tempObj, Value) = S_OK) do begin lSObject := IUnknown(tempObj) as SWBemObject; lpropSet := lSObject.Properties_; propEnum := (lpropSet._NewEnum) as IEnumVariant; while (propEnum.Next(1, tempObj, Value) = S_OK) do begin lSProp := IUnknown(tempObj) as SWBemProperty; if VarIsNull(lSProp.Get_Value) then sValue := '<empty>' else case lSProp.CIMType of wbemCimtypeSint8, wbemCimtypeUint8, wbemCimtypeSint16, wbemCimtypeUint16, wbemCimtypeSint32, wbemCimtypeUint32, wbemCimtypeSint64: if VarIsArray(lSProp.Get_Value) then begin if VarArrayHighBound(lSProp.Get_Value, 1) > 0 then for Count := 1 to VarArrayHighBound(lSProp.Get_Value, 1) do sValue := sValue + ' ' + IntToStr(lSProp.Get_Value[Count]); end else sValue := IntToStr(lSProp.Get_Value); wbemCimtypeReal32, wbemCimtypeReal64: sValue := FloatToStr(lSProp.Get_Value); wbemCimtypeBoolean: if lSProp.Get_Value then sValue := 'True' else sValue := 'False'; wbemCimtypeString, wbemCimtypeUint64: if VarIsArray(lSProp.Get_Value) then begin if VarArrayHighBound(lSProp.Get_Value, 1) > 0 then for Count := 1 to VarArrayHighBound(lSProp.Get_Value, 1) do sValue := sValue + ' ' + lSProp.Get_Value[Count]; end else sValue := lSProp.Get_Value; wbemCimtypeDatetime: sValue := lSProp.Get_Value; wbemCimtypeReference: sValue := lSProp.Get_Value; wbemCimtypeChar16: sValue := '<16-bit character>'; wbemCimtypeObject: sValue := '<cim Object>'; else sValue := 'Unknown type'; end; {case} // fill the property name & its value to ValueListEditor vleCPUInfo.Strings.Add(lsProp.Name + '=' + sValue); end; {while propEnum} end; {while Enum} finally FLocator.Disconnect; Screen.Cursor := crDefault; end; {try} end; end.
New Theme
We’ve just created a new theme called Borland Delphi 2005. It still under development cycle, but you can see how it works on this site.
If the codes are mature, I will release it.
Regards.
Delfai, Delfi or Delpi..???
Menurut Anda, bagaimanakah pengucapan Delphi yang benar..?? Pernahkah terlintas dalam benak Anda mencari tahu pengucapan Delphi yang tepat..? Atau menurut Anda bahwa kata Delphi yang Anda ucapkan sudah tepat..? Mmm, cukup sulit untuk menjawabnya karena fakta yang saya temukan ternyata berbeda – beda, bahkan dari para master dan dedengkot Delphi sekalipun.
Fakta ini saya dapat ketika saya menyimak tutorial yang disampaikan oleh para master, terutama pada BDNradio maupun BDNtv. Mereka mengucapkan Delphi dengan lafal yang berbeda. Beberapa arsitek Delphi di US melafalkannya dengan “Delfai”, sedangkan anggota Borland yang ada di Eropa, bahkan Marco Cantu pun menyebutnya dengan “Delfi”. Sementara itu kebanyakan orang Indonesia menyebutnya dengan “Delpi”.
Nah lalu bagaimana dengan Anda..??
My Dates With Delphi
Suatu ketika teman saya bertanya mulai kapan saya menggunakan Delphi. Lalu saya jawab sejak Delphi mulai ada, alias Delphi 1. Kaget juga mendengar jawaban saya seakan tidak percaya bahwa saya yang sedang asik coding pada Delphi 2005 ternyata pengguna Delphi sejak awal.
Sebenarnya perkenalan saya dengan Delphi melalui Turbo Pascal. Waktu itu kalau tidak salah belajar TP3, kemudian TP5 dan TP7. Nah pada TP7 ini Borland memperkenalkan konsep baru Object Oriented Programming melalui TurboVision. Setelah TV, saya coba Borland Pascal for Windows, gak banyak yang berubah bila dibanding TP7, cuma GUI nya saja yang menyesuaikan.
Nah baru setelah itu Borland merilis Borland Delphi 1, Rapid Application Development (RAD) yang bener – bener killer (pada jamannya). Utak – utik, ternyata asik juga. Kemudian saya langsung ke Delphi 3, dulu saya masih ingat code name-nya Ivory. Kemudian berturut – turut saya mencoba Delphi 4 dan 5. Versi 6 saya lompati dan langsung ke Delphi 7 dan Delphi 9.
Adapun beberapa versi Dlephi yang saya lewati, yaitu versi 2 dan 6 karena waktu itu saya kurang waktu untuk pemrograman, waktu itu karena sibuk kuliah (v2) dan bekerja di bagian keuangan (v6). Untuk versi 8 saya lewati karena ‘kekecewaan’ (setelah mencoba beberapa kali) saya yang hanya mengakomodir platform .NET saja, disamping tampilan IDE yang tidak seperti biasanya, yaitu mirip Visual Basic.
Versi 9 alias 2005 membawa banyak perubahan, antara lain ECO, Unit Testing, Refactoring, Code Folding, .NET, multiple language dalam satu IDE (C#, .NET, Win32), Dokumentasi yang lebih baik, optimalisasi complier dan native code, integrasi dengan aplikasi dari Borland lain seperti Caliber, StarTeam dan masih banyak fitur yang apabila saya sebutkan satu persatu akan menghabiskan puluhan halaman. Intinya adalah, Delphi2005 kembali menjadi Killer Application setelah 3 tahun vakum (setelah Delphi7) dan pasarnya diambil alih oleh Microsoft dengan VisualStudio nya.
Yah begitulah sekelimut ‘kencan’ saya dengan Delphi.
New Looks and Feels
Ah, setelah menggunakan theme standar, kini saatnya melakukan enhancement, pengubahan theme dan instalasi beberapa plugin untuk meningkatkan kapabilitas wordpress.
< ?php $hello =& new HelloWorld(); while(!$hello->hasSaidHello()) { $hello->sayHello(); $hello->sayHowAreYa(); } $hello->sayBye(); unset($hello); ?>
happy surf and enjoy your day..