convert decimal input to hexadecimal variable? - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

convert decimal input to hexadecimal variable?

Im still very new to programming and im trying to convert a decimal input from a ttedit, and i was wondering if im heading in the right direction with what iv tried so far, so would someone have a look at it for me and let me know were im going wrong if possible or if my whole idea is wrong please.

this is what iv tried so far.
[code]unit Trainer_new_code;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, tlhelp32, StdCtrls, ExtCtrls, DB, DBTables, dblookup;

type
TForm2 = class(TForm)
Button1: TButton;
Table1: TTable;
DataSource1: TDataSource;
Button2: TButton;
DBLookupCombo1: TDBLookupCombo;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;
PidHandle: integer;
PidID : integer;
data : string;
//variable containing string converted to integer
ICINT : integer;
//Variable containing string converted to hex
ICHEX : string;
Const
ProgramName = '_suIlluminus.exe';


implementation

{$R *.dfm}
//Find process
function GetProcessID(Const ExeFileName: string; var ProcessId: integer): boolean;

//procedure for 4bytes
procedure poke4(Address: Cardinal; Data: Cardinal);
var
Written: Cardinal;
begin
WriteProcessMemory(PidHandle, Pointer(Address), @Data, SizeOf(Data), Written);
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
if GetProcessID(ProgramName, PidId) then
begin
ICINT := StrToInt(edit2.Text);
ICHEX := IntToHex(ICINT,4);
PidHandle := OpenProcess(PROCESS_ALL_ACCESS,False,PidId);
//this is my main problem it wont accept a variable
//as a hexadecimal value but i need it to be a variable
//not a set value. Have tried variable types Word,string,cardinal.
poke4($44f6354,$ICHEX);
end else
begin
MessageDlg('Start Process First.', mtwarning, [mbOK],0);
end;
end;


end.[/code]

I hope someone can help iv not been able to find any other post on a variety of websites with a helpful answer.
thank you in advance

Comments

  • FabianClassenFabianClassen Posts: 3Member
    Hi
    there are two things I want to say:
    The first one: Please rename your components.
    You must be able to identify the function of the component only by reading the name ... do you understand? The best possibility to implement that is using prefixes.
    Maybe you can change the name of Button1 to Btn_Convert - so you are able to realise the purpose of the button only by reading the name.

    My second concern: I believe you've tried to do a very hard way. The direction you've chosen is to hard for a beginner.
    Here is a simple program which I programmed a long time ago:

    Please try to understand! If there was questions I would be happy if you contact me.

    [code]
    unit DezToHex_Unit;

    interface

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

    type
    TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Ed_Eingabe: TEdit;
    Btn_Rechnen: TButton;
    Label4: TLabel;
    Ed_Ausgabe: TEdit;
    Btn_Zurueck: TButton;
    Btn_Ende: TButton;
    procedure Btn_EndeClick(Sender: TObject);
    procedure Btn_ZurueckClick(Sender: TObject);
    procedure Btn_RechnenClick(Sender: TObject);
    private
    { Private-Deklarationen }
    public
    { Public-Deklarationen }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.Btn_EndeClick(Sender: TObject);
    begin
    Close;
    end;

    procedure TForm1.Btn_ZurueckClick(Sender: TObject);
    begin
    Ed_Eingabe.Clear;
    Ed_Ausgabe.Clear;
    end;

    procedure TForm1.Btn_RechnenClick(Sender: TObject);
    var
    Zahl: Integer;
    Hex: String;
    begin
    Zahl := StrToInt(Ed_Eingabe.Text);
    Hex := '';
    While Zahl >= 1 do
    begin
    Case Zahl mod 16 of
    0: Hex := '0' + Hex;
    1: Hex := '1' + Hex;
    2: Hex := '2' + Hex;
    3: Hex := '3' + Hex;
    4: Hex := '4' + Hex;
    5: Hex := '5' + Hex;
    6: Hex := '6' + Hex;
    7: Hex := '7' + Hex;
    8: Hex := '8' + Hex;
    9: Hex := '9' + Hex;
    10: Hex := 'A' + Hex;
    11: Hex := 'B' + Hex;
    12: Hex := 'C' + Hex;
    13: Hex := 'D' + Hex;
    14: Hex := 'E' + Hex;
    15: Hex := 'F' + Hex;
    end;
    Zahl := Zahl div 16;
    end;
    Ed_Ausgabe.Text := Hex;
    end;

    end.
    [/code]

    Please notice that the names of the components are in German language.

    Fabian Classen

    PS: I hope you are able to understand my "bad" english
  • bondy2007bondy2007 Posts: 4Member
    edited rerad your post misunderstood what you wanted to do
Sign In or Register to comment.