Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
convert decimal input to hexadecimal variable? Posted by manimal555 on 17 Mar 2009 at 4:14 PM
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.
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.


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
Report
Re: convert decimal input to hexadecimal variable? Posted by FabianClassen on 17 Apr 2009 at 2:57 AM
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.

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.


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
Attachment: DezToHex_Projekt.zip (160069 Bytes | downloaded 253 times)
Report
Re: convert decimal input to hexadecimal variable? Posted by bondy2007 on 30 Apr 2009 at 8:45 AM
edited rerad your post misunderstood what you wanted to do



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.