Hello all. I am trying to make a GUI program that converts a number into it's hexademical form. I was able to do this sucessfully in a pascal TUI program I made a while back, but cannot seem to apply the same logic in Object Pascal.
In my TUI pascal program I was able to convert from Int to Hex like this:
var
intNum, hexNum : Int64;
begin
intNum := 12345;
hexNum := 0;
hexNum := IntToHex(intNum, 4);
end.
In my Object Pascal GUI program I have 2 Edit boxes and a Button and upon clicking the Button I would like the number in Edit box 1 to be converted and display the hex form in Edit box 2.
Initially I tried this method to convert the String to an Integer:
var
num1, num2 : Integer;
begin
num1 := StrToInt(Edit1.Text);
end.
However with this method I wasn't able convert from Int to Hex using:
var
num1, num2 : Integer;
begin
num2:= IntToHex(num1, 4);
end.
This method unfortunately gave me a the following message which I don't get because I thought my earlier code converted the string into an Integer?
Error: Incompatible types: got "AnsiString" expected "LongInt"
My second attempt was to use a Turbo Pascal (new to me) method to convert from String to Integer, but got the same error message as above.
Val(Edit1.Text, num1, ErCode);
if ErCode <> 0 then
ShowMessage('Number cannot be converted');
hexNum := IntToHex(num1, 4);
Number conversion is not a strong area of mine and any help would be greatly appreciated.