Emmerisch
Members-
Content Count
3 -
Joined
-
Last visited
Community Reputation
0 Neutral-
if you count with 0 both are 15
-
Thanks for the help, I've now changed the power variable to power1 and the first two error messages have gone. Now the third and 2 new are there, which apparently really is from the code: hexToBinary: array['0'..'F'] of string = ('0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'); and: binaryToHex: array['0000'..'1111'] of Char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); The Errors are: [Error] Unit2.pas(99): Number of elements is different from declaration [Error] Unit2.pas(110): Incompatible types: 'Integer' and 'String' [Error] Unit2.pas(111): Number of elements is different from declaration Line 99 is: '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'); Line 110 is: binaryToHex: array['0000'..'1111'] of Char = Line 111 is: ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); I don't know why Delphi thinks this is a problem because 0-F equals 0000-1111 digits. Both are 16, i.e.: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' = 16 numbers and '0000', '0001','0010', '0011', '0100', '0101','0110' , '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'=16 numbers. I just don't see anything wrong in that.
-
Hello, I was making a program for school and I saw three error messages that I couldn't easily fix. These 3 are as a Screenshot in the Attachment. Can anyone tell me how I can fix this error´s. I also need to say that I only have Delphie 6 Profesionale and no later Version. To the Program: The program should be able to convert numbers under the number systems: decimal, binary and hexadecimal. Here is the program code: unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Math, Buttons; type TForm1 = class(TForm) ComboBox1: TComboBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Edit1: TEdit; BitBtn1: TBitBtn; Label5: TLabel; BitBtn2: TBitBtn; Label6: TLabel; procedure BitBtn1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } function DecimalToBinary(decimal: Integer): string; end; var Form1: TForm1; iSelect: Integer; implementation {$R *.dfm} function TForm1.DecimalToBinary(decimal: Integer): string; var remainder: Integer; begin Result := ''; while decimal > 0 do begin remainder := decimal mod 2; Result := IntToStr(remainder) + Result; decimal := decimal div 2; end; end; function BinaryToDecimal(binary: string): Integer; var i, power, digit: Integer; begin Result := 0; power := Length(binary) - 1; for i := 1 to Length(binary) do begin digit := StrToInt(binary[i]); Result := Result + (digit * Trunc(Power(2, power))); Dec(power); end; end; function DecimalToHexadecimal(decimal: Integer): string; const hexDigits: array[0..15] of Char = '0123456789ABCDEF'; var remainder: Integer; begin Result := ''; while decimal > 0 do begin remainder := decimal mod 16; Result := hexDigits[remainder] + Result; decimal := decimal div 16; end; end; function HexadecimalToDecimal(hexadecimal: string): Integer; var i, power, digit: Integer; begin Result := 0; power := Length(hexadecimal) - 1; for i := 1 to Length(hexadecimal) do begin if hexadecimal[i] in ['0'..'9'] then digit := Ord(hexadecimal[i]) - Ord('0') else digit := Ord(hexadecimal[i]) - Ord('A') + 10; Result := Result + (digit * Trunc(Power(16, power))); Dec(power); end; end; function HexadecimalToBinary(hexadecimal: string): string; const hexToBinary: array['0'..'F'] of string = ('0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'); var i: Integer; begin Result := ''; for i := 1 to Length(hexadecimal) do Result := Result + hexToBinary[hexadecimal[i]]; end; function BinaryToHexadecimal(binary: string): string; const binaryToHex: array['0000'..'1111'] of Char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); var i: Integer; paddedBinary: string; begin Result := ''; paddedBinary := binary; while Length(paddedBinary) mod 4 <> 0 do paddedBinary := '0' + paddedBinary; for i := 1 to Length(paddedBinary) div 4 do Result := Result + binaryToHex[Copy(paddedBinary, (i - 1) * 4 + 1, 4)]; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin iSelect := ComboBox1.ItemIndex; Label4.Caption := Edit1.Text; if iSelect = 0 then begin Label6.Caption := 'dez ---> bin'; Label1.Caption := DecimalToBinary(StrToInt(Edit1.Text)); end; if iSelect = 1 then begin Label6.Caption := 'dez ---> hex'; Label1.Caption := DecimalToHexadecimal(StrToInt(Edit1.Text)); end; if iSelect = 2 then begin Label6.Caption := 'bin ---> dez'; Label1.Caption := BinaryToDecimal(StrToInt(Edit1.Text)); end; if iSelect = 3 then begin Label6.Caption := 'bin ---> hex'; Label1.Caption := BinaryToHexadecimal(StrToInt(Edit1.Text)); end; if iSelect = 4 then begin Label6.Caption := 'hex ---> dez'; Label1.Caption := HexadecimalToDecimal(StrToInt(Edit1.Text)); end; if iSelect = 5 then begin Label6.Caption := 'hex ---> bin'; Label1.Caption := HexadecimalToBinary(StrToInt(Edit1.Text)); end; end; end. I know the Errors are written in German. Here are the Errors in English: [Error] Unit2.pas(58): Missing operator or semicolon [Error] Unit2.pas(90): Missing operator or semicolon [Error] Unit2.pas(99): Number of elements is different from declaration bye.