Archive

Archive for September, 2008

How to Select a “Bar” in the TChart Delphi control

September 26, 2008 Leave a comment

Reference : http://delphi.about.com/od/adptips2006/qt/chart_selectbar.htm

Tip submitted by Meze Calin Nicolae

Here’s a method of simulating a selection in the TChart Delphi control. When a user clicks on a bar of a chart, the respective bar changes its color.

Everything is being done using one event, the onClickSeries, which provides us the index of the clicked bar.

Follow the steps:

  • Drop a TChart (“Additional” tab) control on a Delphi form.
  • Add one (empty) series to the Chart.
  • Select a “Bar” chart style.

Declare two form level variables:

colors : array of TColor;
k : integer;

Fill in the Chart with some “dummy” data in the Form’s OnCreate event:

procedure TChartForm.FormCreate(Sender: TObject) ;
begin
  SetLength(colors,7) ;
  for k := 0 to 6 do colors[k] := clBlue;

  Chart1.Series[0].Add(10,’test2′,Colors[0]) ;
  Chart1.Series[0].Add(70,’test3′,Colors[1]) ;
  Chart1.Series[0].Add(90,’test4′,Colors[2]) ;
  Chart1.Series[0].Add(40,’test5′,Colors[3]) ;
  Chart1.Series[0].Add(66,’test6′,Colors[4]) ;
end;

Handle the OnClickSeries event as:

procedure TChartForm.Chart1ClickSeries(
  Sender: TCustomChart;
  Series: TChartSeries;
  ValueIndex: Integer;
  Button: TMouseButton;
  Shift: TShiftState;
  X, Y: Integer) ;
begin
  for k := 0 to 6 do
  if k <> ValueIndex then
    colors[k] := clBlue
  else
    colors[k] := clRed;

  Chart1.Series[0].Clear;
  Chart1.Series[0].Add(10,’test2′,Colors[0]) ;
  Chart1.Series[0].Add(70,’test3′,Colors[1]) ;
  Chart1.Series[0].Add(90,’test4′,Colors[2]) ;
  Chart1.Series[0].Add(40,’test5′,Colors[3]) ;
  Chart1.Series[0].Add(66,’test6′,Colors[4]) ;
end;

Categories: Delphi Tags: ,

di temukan Batuan tertua di dunia

September 26, 2008 Leave a comment
Reference : http://kompas.com/read/xml/2008/09/26/11544675/ditemukan.batu.tertua.di.bumi
Ditemukan, Batu Tertua di Bumi

Bagian dari batu tertua di Bumi yang usianya 4,28 miliar tahun.
JUMAT, 26 SEPTEMBER 2008 | 11:54 WIB

QUEBEC, JUMAT — Para ilmuwan telah menemukan batuan yang hingga saat ini diyakini sebagai batu tertua di Bumi. Usianya yang mencapai 4,28 miliar tahun membuat batu itu lebih tua 250 juta tahun dibanding batu-batu tua yang ditemukan sebelumnya.

Menurut perhitungan ilmiah, Bumi terbentuk sekitar 4,6 miliar tahun lalu dari piringan debu dan gas yang mengelilingi Matahari. Namun sisa-sisa dari bongkahan batu Bumi yang asli amat sulit ditemukan karena sebagian besar materinya terdaur ulang oleh perut Bumi akibat gerakan lempeng tektonik yang terus-menerus mengubah permukaan Bumi.
  
Pada tahun 2001, para ahli geologi menemukan lempengan batu yang dikenal sebagai sabuk hijau Nuvvuagittuq di pesisir timur Hudson Bay, Quebec utara. Menduga bahwa batu-batu di sana mungkin berasal dari periode awal terbentuknya Bumi, para pekerja geologi menelitinya untuk menentukan usianya. Mereka mengukur variasi-variasi kecil isotop (bagian unsur yang memiliki jumlah netron berbeda) dari elemen langka Bumi, neodymium dan samarium, dalam batuan itu dan memastikan bahwa batuan itu berusia 3,8 hingga 4,28 miliar tahun.

Umur tertua, berasal dari batu yang disebut “faux amphibolite”, diyakini sebagai endapan vulkanis kuno. Batu ini mengalahkan batu yang dianggap tertua sebelumnya, dengan usia 4,03 miliar tahun dan berasal dari formasi yang disebut Acasta Gneiss, Wilayah barat laut Kanada.

Satu-satunya materi awal yang lebih tua dibanding batu Nuvvuagittuq adalah zircon dari butiran mineral terisolisasi yang tahan terhadap cuaca dan proses geologi. Zircon tertua dari butiran-butiran di Australia Barat usianya sekitar 4,36 miliar tahun.

Batu Nuvvuagittuq adalah batu tertua yang ditemukan sampai saat ini, menurut ahli geologi Richard Carlson dari Carnegie Institution, yang menganalisa batu itu bersama Jonathan O’Neil, mahasiswa doktoral di McGill University Montreal. Penelitian mereka diumumkan di jurnal Science yang terbit 25 September ini.

Categories: Lingkungan Tags:

Pengerukan pasir pantai geger Mempercepat Kerusakan Bali

September 26, 2008 Leave a comment

Reference : http://www.balipost.com

 Berita Nusantara
Jumat, 26 September 2008 | BP
Pengerukan Pasir Pantai Geger
Mempercepat Kerusakan Bali
Prediksi kawasan Bali Selatan, termasuk Kuta, akan tergenang air pada tahun 2030-an sempat mencuat dalam diskusi terbatas tentang lingkungan di Bali Post, dua tahun lalu. Saat itu, Kepala Pusreg Lingkungan Hidup Bali-Nusra R. Sudirman menyatakan, berdasarkan kajian-kajian ilmiah dan fenomena alam secara global, Bali Selatan berpotensi tergenang air alias tenggelam. Ia pun merekemondasikan agar semua kabupaten/kota di Bali memperbanyak kawasan tutupan sebagai upaya melakukan pengendalian kerusakan lingkungan yang bisa mempercepat peningkatan volume air laut. Adakah pengerukan pasir pantai Geger akan mempercepat naiknya air di Kuta?

AHLI geomorfologi Unud R. Suyarto mengingatkan kekhawatiran banyak kalangan atas dampak pengerukan pasir pantai Geger layak menjadi perhatian pemberi izin, dalam hal ini Bupati Badung. Masalahnya, teknis pengerukan yang akan dilakukan tidak jelas. Kajian terhadap kondisi pantai Geger juga tak pernah disampaikan kepada publik secara utuh. Padahal ketika amdal dibuat, wajib hukumnya ada sosialisasi secara terbuka, untuk menghindari terjadinya manipulasi terhadap potensi dan risiko. ‘Proses pengerukan ini kemungkinan besar tanpa dibarengi pengawasan teknis oleh pemberi izin. Ini jelas akan berpotensi menimbulkan kerusakan pesisir,’ ujarnya.

Ketua Walhi Bali Agung Wardana mengatakan, dalam urusan pengelolaan kekayaan alam adalah hak masyarakat untuk memperoleh informasi lingkungan, khususnya amdalnya. Dalam UU Pengelolaan Lingkungan Hidup, masyarakat mempunyai hak berpartisipasi dalam pengelolaan lingkungan hidup. Bentuk partisipasi tersebut adalah hak untuk terlibat dalam memberikan masukan sebelum pengambilan kebijakan. ‘Sekali lagi, ini sebuah pelanggaran atas hak yang tak memberikan kesempatan masyarakat untuk mendapatkan informasi,’ tukasnya.

Suyarto yang juga peneliti PPLH Unud ini mendukung penyetopan pengerukan pasir sampai adanya proses kajian yang transparan atas kandungan pasir di pantai Geger. ‘Pengerukan pasir di laut lepas harus dilihat apakah pasir itu masih berkaitan dengan pantai atau tidak. Yang pasti dampak pengerukan pasir yang tak sesuai prosedur teknis akan sangat berisiko,’ ujarnya.

Menyinggung apakah pengerukan ini berpotensi terjadinya percepatan prediksi Bali Selatan termasuk Kuta tenggelam? Suyarto mengatakan itu sangat tergantung dari perilaku pengelolaannya. ‘Pengerukan pasir di Bali Selatan jelas berisiko bagi Bali,’ ujarnya. (044/029)

Categories: Lingkungan Tags: , ,

Capturing a Screen Shot of a TWebBrowser Content (Web Page) in Delphi

September 26, 2008 Leave a comment

Reference : http://delphi.about.com/od/vclusing/a/wb_scren_shot.htm

The TWebBrowser Delphi control provides access to the Web browser functionality from your Delphi apps – to allow you to create a customized Web browsing application or to add Internet, file and network browsing, document viewing, and data downloading capabilities to your applications.

Web Page Screen Shot

You might need to programmatically grab the screen shot of the current page loaded in the web browser control.A screen shot (screen capture) is a copy of the screen’s contents that can be saved as a graphics file. 
Web Browser screen shot is a graphics copy of the content on the web browser control – usually a web page (document).

The custom function WebBrowserScreenShot will capture the contents of a TWebBrower’s client area into a JPEG image and save it to a specified file.

uses ActiveX;

procedure WebBrowserScreenShot(const wb: TWebBrowser; const fileName: TFileName) ;
var
  viewObject : IViewObject;
  r : TRect;
  bitmap : TBitmap;
begin
  if wb.Document <> nil then
  begin
    wb.Document.QueryInterface(IViewObject, viewObject) ;
    if Assigned(viewObject) then
    try
      bitmap := TBitmap.Create;
      try
        r := Rect(0, 0, wb.Width, wb.Height) ;

        bitmap.Height := wb.Height;
        bitmap.Width := wb.Width;

        viewObject.Draw(DVASPECT_CONTENT, 1, nilnil, Application.Handle, bitmap.Canvas.Handle, @r, nilnil, 0) ;

        with TJPEGImage.Create do
        try
          Assign(bitmap) ;
          SaveToFile(fileName) ;
        finally
          Free;
        end;
      finally
        bitmap.Free;
      end;
    finally
      viewObject._Release;
    end;
  end;
end;

Note: JPEG images are smaller when compared to BMPs – this is why the BMP object is converted to a JPG before saving to the disk.A sample usage: navigate to a web site in the form’s OnCreate event, take the screen shot in the webbrowser’s OnNavigateComplete2 event:

procedure TForm1.FormCreate(Sender: TObject) ;
begin
  WebBrowser1.Navigate(‘http://delphi.about.com&#8217;) ;
end;

procedure TForm1.WebBrowser1NavigateComplete2(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant) ;
begin
  WebBrowserScreenShot(WebBrowser1,’c:\WebBrowserImage.jpg’) ;
end;

Note: the code above saves the “http://delphi.about.com&#8221; site’s screen shot to a file named WebBrowserImage.jpg on the C drive.

Take a Screen Shot of an Inactive Window

September 26, 2008 Leave a comment

Reference : http://delphi.about.com/od/delphitips2008/qt/print_window.htm

Taking a screen shot of a window using Delphi code is rather easy. 
A screen shot (screen capture) is a copy of the screen’s contents that can be saved as a graphics file or displayed in a graphics “aware” control, for example TImage.

In most cases you will want to take a screen shot of the active window or the Windows Desktop.

What if you need to do a screen capture of all the running applications – most of them will be inactive and not visible to the user?

WindowSnap – Inactive Window Screen Capture

Windows XP also introduces the new printing API, PrintWindow. This API enables the caller to snapshot a visual copy of a window into a device context.Drop a TImage (named “Image1”) on a form and use the following code:

WindowSnap(Self.Handle, Image1.Picture.Bitmap) ;
Image1.Refresh;

The actual WindowSnap function is defined as:

function WindowSnap(windowHandle: HWND; bmp: TBitmap): boolean;
var
  r: TRect;
  user32DLLHandle: THandle;
  printWindowAPI: function(sourceHandle: HWND; destinationHandle: HDC; nFlags: UINT): BOOL; stdcall;
begin
  result := False;
  user32DLLHandle := GetModuleHandle(user32) ;
  if user32DLLHandle <> 0 then
  begin
    @printWindowAPI := GetProcAddress(huser32, ‘PrintWindow’) ;
    if @printWindowAPI <> nil then
    begin
      GetWindowRect(windowHandle, r) ;
      bmp.Width := r.Right – r.Left;
      bmp.Height := r.Bottom – r.Top;
      bmp.Canvas.Lock;
      try
        result := printWindowAPI(windowHandle, bmp.Canvas.Handle, 0) ;
      finally
        bmp.Canvas.Unlock;
      end;
    end;
  end;
end; (*WindowSnap*)

Note that the first parameter to the WindowSnap procedure is a HWND value (THandle) – the handle of the window you want to capture.WinDowse is an extremely convenient and easy to use tool for obtaining necessary technical information about any window (handle, child windows, etc.)

Here’s an idea: enumerate top-level windows (to grab their handles) and create your own task-switcher 🙂

Categories: API Tags: ,

F-117A Nighthawk – 2006 Chicago Air Show

September 25, 2008 Leave a comment

Vodpod videos no longer available.

Categories: Uncategorized

Display an Error Message for an OS Error Code

September 25, 2008 Leave a comment

Delphi’s SysErrorMessage function converts OS error codes into a string – an error message string that corresponds to the specified OS error code..

GetLastError returns the last error reported by an operating system API call.

Note: calling getLastError resets the operating system error state – do not call it two times “in a row” – the second call will clear the “first” error.

Convert the OS Error Code into a User Friendly Message

Here’s a quick example – trying to delete a non existing folder. RemoveDir deletes an existing empty directory. The return value is true if a new directory was successfully deleted, false if an error occurred. Read GetLastError to find out why an error occurred.

RemoveDir(‘c:\NoSuchFolder’) ;

ShowMessage(‘System Error Message: ‘+ SysErrorMessage(GetLastError)) ;

Categories: error Tags: ,

Graphical progress Bar for Delphi application

September 25, 2008 Leave a comment

reference : http://delphi.about.com/od/delphitips2008/qt/image-progress.htm

 

When your application performs a time-consuming operation, you can use a progress bar, the TProgressBar Delphi control, to show how much of the task is completed.

When you do not know how many steps are needed for a progress bar – you might want to display a continuous bar – or a moving graphical object. The UpdateImageProgress takes a reference to a TImage control displaying a picture. By calling the procedure from inside, for example, a timer event (TTimer control), a graphical progress effect is achieved.

The UpdateImageProgress shifts the image to the right – using the boundaries of the image – thus creating a continuous progress bar.

//”moves” image to the right in “step” steps
procedure UpdateImageProgress(const img : TImage) ;
const
  step = 4;
var
  b : TBitmap;
begin
  with img.Picture.Bitmap do
  begin
    b := TBitmap.Create;
    try
      b.Width := Width;
      b.Height := Height;
      BitBlt(b.Canvas.Handle, step, 0, Width-step, Height, Canvas.Handle, 0, 0, SRCCOPY) ;
      BitBlt(b.Canvas.Handle, 0, 0, step, Height, Canvas.Handle, Width-step, 0, SRCCOPY) ;
      Assign(b) ;
    finally
      FreeAndNil(b) ;
    end;
  end;
end;

UpdateImageProgress shifts the trailing “step” part of the bitmap to the front, moving the rest along.

Categories: Progress bar Tags: ,

Get the control Under Mouse in a Delphi application

September 25, 2008 1 comment

Reference : http://delphi.about.com/od/delphitips2008/qt/find-vcl-window.htm

 

If, in your Delphi application you need to know what control is “under” the mouse while the mouse is being moved over the application, you can use RTL’s FindVCLWindow function.

FindVCLWindow

The VCLWindow function can locate the windowed control under a certain point – for example under the mouse pointer. You can use FindVCLWindow to identify the windowed control that is under the mouse from another control that has captured the mouse. The Pos parameter specifies the location that must be over the returned windowed control. If there is no windowed control under the Pos parameter, FindVCLWindow returns nil.For an example have a TApplicationEvents component on the main form of the application and handle its OnIdle event as:

//Handles OnIdle event of the ApplicationEvents1 control the MainForm
procedure TMainForm.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean) ;
var
  ctrl : TWinControl;
begin
  ctrl := FindVCLWindow(Mouse.CursorPos) ;

  if ctrl <> nil then
  begin
    Caption := ctrl.Name;

    //do something if mouse is over TLabeledEdit
    if ctrl is TLabeledEdit then
    begin
      Caption := TLabeledEdit(ctrl).Text;
    end;
  end;
end;

Note: Mouse.CursorPos returns the coordinate of the mouse pointer related to the screen.

Categories: Mouse Tags: ,