Friday 28 May 2010

Example program of using BinaryToInteger.DLL

In this example, we are going to create a program that can convert an eight binary data into an integer value using BinaryToInteger.DLL. Before we start, you have to create a user interface like this picture.

Every edit box holds a bit of binary data. So there is a byte binary data (8 bits) that will be converted into an integer value. A binary data holds ‘0’ or ‘1’, so we need to limit the input of each edit box. And the code will be :

procedure TForm1.bit8KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in ['0','1',#8,#13]) then 
    key:=#0
      else
        bit7.SetFocus;
end;

To use BinaryToInteger.DLL, you must declare the function after {$R *.DFM}

{$R *.DFM}
function BinToInt(S : String): integer; stdcall; external 'BinaryToInteger.dll';

Don forget, you must place your BinaryToInteger.DLL in the same folder with this project, or you can place this DLL file in the directory : c:\windows\system.

The code of OnClick even of ConvertButton :

procedure TForm1.ConvertButtonClick(Sender: TObject);
var
  BinaryData : string;
begin
  BinaryData := bit8.Text + bit7.Text + bit6.Text + bit5.Text +
  b it4.Text + bit3.Text + bit2.Text + bit1.Text;
  IntegerValue.Caption := IntToStr(BinToInt(BinaryData));  
end;

You can download the complete code of this example program here.

6 comments:

  1. wah, sumpah gak ngerti ...

    ReplyDelete
  2. pakde mampir lagi untuk menimba ilmu, boleh donk

    moga sukses selalu kawan

    ReplyDelete
  3. code2 seperti ini softwarenya pakai apa yah sob ?

    ReplyDelete
  4. jika benrkenan follow balik yah ?

    ReplyDelete
  5. baru lihat codenya aja dah ngelu pol sob

    ReplyDelete
  6. saya menyimak aja Sob, soalnya belum ngerti...

    sukses Sob...

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.