Jumat, 30 April 2021

konversi nilai variabel byte dan integer pada delphi 10

copas kode dibawah ini :
uses
  System.SysUtils;

var
  // Declare two of the basic intrinsic types that have helpers.
  // The others are: ShortInt, SmallInt, Word, Cardinal, NativeInt, NativeUInt and Int64.
  // The methods used in this code example apply to all the types mentioned above.
  myByte: Byte;
  myInteger: Integer;

const
  myString: String = '12345678910111211314';

begin
  try
  myByte := myByte.MaxValue; //255
  myInteger := myInteger.MaxValue;  //2147483647

  writeln('Byte value: ', myByte);
  writeln('Byte value as hexadecimal string using four digits: ',
    myByte.ToHexString(Integer(4)));
  writeln('Byte value as string: ', myByte.ToString());

  // Tries to convert myString to an Integer.
  if myInteger.TryParse(myString, myInteger) then
  begin
    writeln('The new value of myInteger is:', myInteger);
  end
  else
  begin
  //In case the conversion does not succeed,
  //the next statement will try to convert the myByte number
  //to a string.
  //The string returned will be converted to an integer value
  //with the Parse function.
    myInteger := myInteger.Parse(myByte.ToString());
    writeln('The new value of myInteger is:', myInteger);
  end;

  readln;


  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
hasil output program bila dijalankan seperti ini :

Tidak ada komentar:

Posting Komentar