Initially I tried this method to convert the String to an Integer:
num1 := StrToInt(Edit1.Text);
However with this method I wasn't able convert from Int to Hex using:
num2:= IntToHex(num1, 4);
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"
Maybe something like this:
procedure TForm1.Button1Click(Sender: TObject); var Num: Int64; S: string; begin if not(TryStrToInt64(Edit1.Text, Num)) then Exit; S := IntToHex(Num, 4); ShowMessage(S); end;
Initially I tried this method to convert the String to an Integer:
num1 := StrToInt(Edit1.Text);
However with this method I wasn't able convert from Int to Hex using:
num2:= IntToHex(num1, 4);
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"
You do not show the declarations.
StrToInt() converts a string to an Integer, this means that num1 must be declared as an Integer.
IntToHex() converts an Integer to a string, this means than num2 must be declared as a String. Did you do it this way?
I think you are not aware that the bit pattern of an integer does not depend on whether it is displayed as decimal or as hex. The difference is only in the string conversion.
The documentation says so:
https://www.freepascal.org/docs-html/rtl/sysutils/inttohex.html
Still so much more to learn :oGood attitude (not only for you, but also for everybody)! Maybe one more thing: variable naming often leads to misunderstandings. When you name the result variable of the IntToHexfunction "hexNum" then I get the impression that it probably is a "number", maybe an integer or so. But if you name it "hexStr" then it is clear that you want it to be a string.
But if you name it "hexStr" then it is clear that you want it to be a string.Uhm... did you take into account https://www.freepascal.org/docs-html/rtl/system/hexstr.html ?
edit: ah, byte me. That was a silent hint, wasn't it wp ? :-[What do you mean?
I meant the suggestion you made to TS to use the name HexStr for the variable for a better understanding of the purpose/designation of the variable, but at the same time as a silent hint there also exists a function named HexStr ? e.g. would TS search for that specific name then TS would be able to discover that (easily).edit: ah, byte me. That was a silent hint, wasn't it wp ? :-[What do you mean?